Options
All
  • Public
  • Public/Protected
  • All
Menu

Contains tools for encoding/decoding data in different circumstances.

Hierarchy

Implements

Index

Constructors

constructor

Properties

options

toPojoInstance

toPojoInstance: ToPojo<unknown, unknown>

Instance of toPojo to use when serializing objects

Accessors

convertableFormatMimeTypes

  • Combined map of all SerializationFormat and ImageFormat entries to their respective MIME Types

    Returns Map<ConvertableFormat, string>

mimeTypesConvertableFormat

Static ObjectId

  • get ObjectId(): any
  • Returns an instance of the ObjectId constructor bson node module, using the native bson-ext if available.

    Returns any

Static WithDefaults

  • Returns an EncodeTools instance with the default properties

    Returns default

Static Protected bson

  • get bson(): any
  • Returns an instance of the bson node module, using the native bson-ext if available.

    Returns any

Methods

adjustImageBrightness

  • adjustImageBrightness(buffer: Buffer | ArrayBuffer, factor: number, format?: png): Promise<Buffer>
  • adjustImageBrightness(buffer: Buffer | ArrayBuffer, factor: number, format?: jpeg): Promise<Buffer>
  • adjustImageBrightness(buffer: BinaryInputOutput, factor: number, format?: ImageFormat): Promise<Buffer>
  • Adjust brightness of image

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • factor: number
    • Optional format: png

      Format to save result as

    Returns Promise<Buffer>

  • Adjust brightness of image

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • factor: number
    • Optional format: jpeg

      Format to save result as

    Returns Promise<Buffer>

  • Adjust brightness of image

    Parameters

    Returns Promise<Buffer>

compress

  • compress(data: Buffer | ArrayBuffer, format?: lzma, level?: number, ...args: any[]): Promise<Buffer>
  • compress(data: Buffer | ArrayBuffer, format?: zstd, level?: number, ...args: any[]): Promise<Buffer>
  • compress(data: BinaryInputOutput, format?: CompressionFormat, level?: number, ...args: any[]): Promise<Buffer>
  • Compresses arbitrary data using the provided format and any options

    Parameters

    • data: Buffer | ArrayBuffer

      Data to compress

    • Optional format: lzma

      Format to use

    • Optional level: number
    • Rest ...args: any[]

      Options

    Returns Promise<Buffer>

  • Compresses arbitrary data using the provided format and any options

    Parameters

    • data: Buffer | ArrayBuffer

      Data to compress

    • Optional format: zstd

      Format to use

    • Optional level: number
    • Rest ...args: any[]

      Options

    Returns Promise<Buffer>

  • Compresses arbitrary data using the provided format and any options

    Parameters

    Returns Promise<Buffer>

convertImage

  • convertImage(buffer: Buffer | ArrayBuffer, format?: png): Promise<Buffer>
  • convertImage(buffer: Buffer | ArrayBuffer, format?: jpeg): Promise<Buffer>
  • convertImage(data: BinaryInputOutput, format?: ImageFormat): Promise<Buffer>
  • Saves an image in the provided format, performing no operations on the image

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • Optional format: png

      Format to save result as

    Returns Promise<Buffer>

  • Saves an image in the provided format, performing no operations on the image

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • Optional format: jpeg

      Format to save result as

    Returns Promise<Buffer>

  • Saves an image in the provided format, performing no operations on the image

    Parameters

    Returns Promise<Buffer>

cropImage

  • Crops an image and returns a Buffer containing the result in the provided format

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • dims: CropDims

      Height/Width to resize to

    • Optional format: png

      Format to save result as

    Returns Promise<Buffer>

  • Crops an image and returns a Buffer containing the result in the provided format

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • dims: CropDims

      Height/Width to resize to

    • Optional format: jpeg

      Format to save result as

    Returns Promise<Buffer>

  • Crops an image and returns a Buffer containing the result in the provided format

    Parameters

    Returns Promise<Buffer>

decodeBuffer

  • decodeBuffer(buffer: ArrayBuffer, format?: arrayBuffer, ...args: any[]): Buffer
  • decodeBuffer(buffer: Buffer, format?: nodeBuffer, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: hex, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: base32, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: hashids, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: base64, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: base64url, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: ascii85, ...args: any[]): Buffer
  • decodeBuffer(input: string, format?: ascii85, ...args: any[]): Buffer
  • decodeBuffer(buffer: BinaryInputOutput, format?: BinaryEncoding, ...args: any[]): Buffer
  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • buffer: ArrayBuffer
    • Optional format: arrayBuffer
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • buffer: Buffer
    • Optional format: nodeBuffer
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: hex
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: base32
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: hashids
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: base64
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: base64url
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    • input: string
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns Buffer

  • Decodes binary data from the provided format returning either a node.js buffer.

    Parameters

    Returns Buffer

decodeObject

  • decodeObject<T>(buffer: Buffer, format?: nodeBuffer, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: base64, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: base64url, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: hex, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: base32, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: hashids, ...args: any[]): T
  • decodeObject<T>(buffer: ArrayBuffer, format?: arrayBuffer, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: ascii85, ...args: any[]): T
  • decodeObject<T>(buffer: string, format?: ascii85, ...args: any[]): T
  • decodeObject<T>(inputBuffer: BinaryInputOutput, format?: BinaryEncoding, ...args: any[]): T
  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: Buffer
    • Optional format: nodeBuffer
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: base64
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: base64url
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: hex
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: base32
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: hashids
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: ArrayBuffer
    • Optional format: arrayBuffer
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    • buffer: string
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns T

  • Decodes binary data from the provided format returning either a node.js buffer.

    Type parameters

    • T

    Parameters

    Returns T

decompress

  • decompress(data: Buffer | ArrayBuffer, format: lzma, ...args: any[]): Promise<Buffer>
  • decompress(data: Buffer | ArrayBuffer, format: zstd, ...args: any[]): Promise<Buffer>
  • decompress(data: BinaryInputOutput, format: CompressionFormat, ...args: any[]): Promise<Buffer>
  • Decompresses arbitrary data using the provided format and any options

    Parameters

    • data: Buffer | ArrayBuffer

      Data to decompress

    • format: lzma

      Format to use

    • Rest ...args: any[]

    Returns Promise<Buffer>

  • Decompresses arbitrary data using the provided format and any options

    Parameters

    • data: Buffer | ArrayBuffer

      Data to decompress

    • format: zstd

      Format to use

    • Rest ...args: any[]

    Returns Promise<Buffer>

  • Decompresses arbitrary data using the provided format and any options

    Parameters

    Returns Promise<Buffer>

deserializeObject

  • deserializeObject<T>(data: string | Buffer | ArrayBuffer, serializationFormat?: json): T
  • deserializeObject<T>(data: string | Buffer | ArrayBuffer, serializationFormat?: json5): T
  • deserializeObject<T>(data: Buffer | ArrayBuffer, serializationFormat?: cbor): T
  • deserializeObject<T>(data: Buffer | ArrayBuffer, serializationFormat?: msgpack): T
  • deserializeObject<T>(data: Buffer | ArrayBuffer, serializationFormat?: bson): T
  • deserializeObject<T>(data: Buffer | ArrayBuffer, serializationFormat?: SerializationFormat): T
  • Deserializes an object serialized using one of the available algorithms, returning the result as an object

    Type parameters

    • T

    Parameters

    • data: string | Buffer | ArrayBuffer

      Data to deserialize

    • Optional serializationFormat: json

      Algorithm to deserialize with

    Returns T

  • Deserializes an object serialized using one of the available algorithms, returning the result as an object

    Type parameters

    • T

    Parameters

    • data: string | Buffer | ArrayBuffer

      Data to deserialize

    • Optional serializationFormat: json5

      Algorithm to deserialize with

    Returns T

  • Deserializes an object serialized using one of the available algorithms, returning the result as an object

    Type parameters

    • T

    Parameters

    • data: Buffer | ArrayBuffer

      Data to deserialize

    • Optional serializationFormat: cbor

      Algorithm to deserialize with

    Returns T

  • Deserializes an object serialized using one of the available algorithms, returning the result as an object

    Type parameters

    • T

    Parameters

    • data: Buffer | ArrayBuffer

      Data to deserialize

    • Optional serializationFormat: msgpack

      Algorithm to deserialize with

    Returns T

  • Deserializes an object serialized using one of the available algorithms, returning the result as an object

    Type parameters

    • T

    Parameters

    • data: Buffer | ArrayBuffer

      Data to deserialize

    • Optional serializationFormat: bson

      Algorithm to deserialize with

    Returns T

  • Deserializes an object serialized using one of the available algorithms, returning the result as an object

    Type parameters

    • T

    Parameters

    • data: Buffer | ArrayBuffer

      Data to deserialize

    • Optional serializationFormat: SerializationFormat

      Algorithm to deserialize with

    Returns T

encodeBuffer

  • encodeBuffer(inputBuffer: Buffer | ArrayBuffer, format?: nodeBuffer, ...args: any[]): Buffer
  • encodeBuffer(inputBuffer: Buffer | ArrayBuffer, format?: arrayBuffer, ...args: any[]): ArrayBuffer
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: hex, ...args: any[]): string
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: base64, ...args: any[]): string
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: base32, ...args: any[]): string
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: base64url, ...args: any[]): string
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: hashids, ...args: any[]): string
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: ascii85, ...args: any[]): string
  • encodeBuffer(inputBuffer: string | Buffer | ArrayBuffer, format?: ascii85, ...args: any[]): string
  • encodeBuffer(inputBuffer: BinaryInputOutput, format?: BinaryEncoding, ...args: any[]): BinaryInputOutput
  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: Buffer | ArrayBuffer
    • Optional format: nodeBuffer
    • Rest ...args: any[]

    Returns Buffer

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: Buffer | ArrayBuffer
    • Optional format: arrayBuffer
    • Rest ...args: any[]

    Returns ArrayBuffer

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: hex
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: base64
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: base32
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: base64url
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: hashids
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    • inputBuffer: string | Buffer | ArrayBuffer
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Parameters

    Returns BinaryInputOutput

encodeObject

  • encodeObject<T>(inputObject: T, format?: nodeBuffer, ...args: any[]): Buffer
  • encodeObject<T>(inputObject: T, format?: base64, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: base64url, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: hex, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: base32, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: hashids, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: arrayBuffer, ...args: any[]): ArrayBuffer
  • encodeObject<T>(inputObject: T, format?: ascii85, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: ascii85, ...args: any[]): string
  • encodeObject<T>(inputObject: T, format?: BinaryEncoding, ...args: any[]): BinaryInputOutput
  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: nodeBuffer
    • Rest ...args: any[]

    Returns Buffer

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: base64
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: base64url
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: hex
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: base32
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: hashids
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: arrayBuffer
    • Rest ...args: any[]

    Returns ArrayBuffer

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    • inputObject: T
    • Optional format: ascii85
    • Rest ...args: any[]

    Returns string

  • Encodes binary data using the provided format returning either a node.js buffer, array buffer, or string

    Type parameters

    • T

    Parameters

    Returns BinaryInputOutput

hash

  • Hashes data using the provided algorithm, returning a node.js Buffer.

    Parameters

    Returns Promise<Buffer>

hashObject

  • hashObject(obj: any, algorithm?: HashAlgorithm, ...args: any[]): Promise<Buffer>
  • Hashes an object using the provided algorithm, returning a node.js Buffer.

    Parameters

    Returns Promise<Buffer>

hashString

  • Hashes data using the provided algorithm, returning a node.js Buffer.

    Parameters

    Returns Promise<string>

headerToConvertableFormat

headerToImageFormat

headerToSerializationFormat

resizeImage

  • resizeImage(buffer: Buffer | ArrayBuffer, dims: { height: number; width?: number } | { height?: number; width: number }, format?: png): Promise<Buffer>
  • resizeImage(buffer: Buffer | ArrayBuffer, dims: { height: number; width?: number } | { height?: number; width: number }, format?: jpeg): Promise<Buffer>
  • resizeImage(data: BinaryInputOutput, dims: { height: number; width?: number } | { height?: number; width: number }, format?: ImageFormat): Promise<Buffer>
  • Resizes an image and returns a Buffer containing the result in the provided format

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • dims: { height: number; width?: number } | { height?: number; width: number }

      Height/Width to resize to

    • Optional format: png

      Format to save result as

    Returns Promise<Buffer>

  • Resizes an image and returns a Buffer containing the result in the provided format

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    • dims: { height: number; width?: number } | { height?: number; width: number }

      Height/Width to resize to

    • Optional format: jpeg

      Format to save result as

    Returns Promise<Buffer>

  • Resizes an image and returns a Buffer containing the result in the provided format

    Parameters

    • data: BinaryInputOutput

      Image

    • dims: { height: number; width?: number } | { height?: number; width: number }

      Height/Width to resize to

    • Optional format: ImageFormat

      Format to save result as

    Returns Promise<Buffer>

serializeObject

  • serializeObject<T>(obj: T, serializationFormat?: json, useToPojoBeforeSerializing?: boolean, encodeBuffersWhenUsingToPojo?: boolean): string
  • serializeObject<T>(obj: T, serializationFormat?: json5, useToPojoBeforeSerializing?: boolean, encodeBuffersWhenUsingToPojo?: boolean): string
  • serializeObject<T>(obj: T, serializationFormat?: cbor, useToPojoBeforeSerializing?: boolean, encodeBuffersWhenUsingToPojo?: boolean): Buffer
  • serializeObject<T>(obj: T, serializationFormat?: msgpack, useToPojoBeforeSerializing?: boolean, encodeBuffersWhenUsingToPojo?: boolean): Buffer
  • serializeObject<T>(obj: T, serializationFormat?: bson, useToPojoBeforeSerializing?: boolean, encodeBuffersWhenUsingToPojo?: boolean): Buffer
  • serializeObject<T>(obj: T, serializationFormat?: SerializationFormat, useToPojoBeforeSerializing?: boolean, encodeBuffersWhenUsingToPojo?: boolean): Buffer
  • Serializes an object using one of the available algorithms, returning the result as a Buffer or a string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    • Optional serializationFormat: json

      Algorithm to serialize with

    • Optional useToPojoBeforeSerializing: boolean

      Use toPojo on the object before serializing

    • Optional encodeBuffersWhenUsingToPojo: boolean

    Returns string

  • Serializes an object using one of the available algorithms, returning the result as a Buffer or a string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    • Optional serializationFormat: json5

      Algorithm to serialize with

    • Optional useToPojoBeforeSerializing: boolean

      Use toPojo on the object before serializing

    • Optional encodeBuffersWhenUsingToPojo: boolean

    Returns string

  • Serializes an object using one of the available algorithms, returning the result as a Buffer or a string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    • Optional serializationFormat: cbor

      Algorithm to serialize with

    • Optional useToPojoBeforeSerializing: boolean

      Use toPojo on the object before serializing

    • Optional encodeBuffersWhenUsingToPojo: boolean

    Returns Buffer

  • Serializes an object using one of the available algorithms, returning the result as a Buffer or a string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    • Optional serializationFormat: msgpack

      Algorithm to serialize with

    • Optional useToPojoBeforeSerializing: boolean

      Use toPojo on the object before serializing

    • Optional encodeBuffersWhenUsingToPojo: boolean

    Returns Buffer

  • Serializes an object using one of the available algorithms, returning the result as a Buffer or a string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    • Optional serializationFormat: bson

      Algorithm to serialize with

    • Optional useToPojoBeforeSerializing: boolean

      Use toPojo on the object before serializing

    • Optional encodeBuffersWhenUsingToPojo: boolean

      If true, Buffers will be encoded with this.encodeBuffer when encountered.

    Returns Buffer

  • Serializes an object using one of the available algorithms, returning the result as a Buffer or a string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    • Optional serializationFormat: SerializationFormat

      Algorithm to serialize with

    • Optional useToPojoBeforeSerializing: boolean

      Use toPojo on the object before serializing

    • Optional encodeBuffersWhenUsingToPojo: boolean

      If true, Buffers will be encoded with this.encodeBuffer when encountered.

    Returns Buffer

uniqueId

  • uniqueId(idFormat: uuidv4): Buffer
  • uniqueId(idFormat: uuidv1): Buffer
  • uniqueId(idFormat: uuidv4String): string
  • uniqueId(idFormat: uuidv1String): string
  • uniqueId(idFormat: objectId): Buffer
  • uniqueId(idFormat: nanoid, size?: number): string
  • uniqueId(idFormat: timestamp): number
  • uniqueId(idFormat?: IDFormat, ...args: any[]): string | number | Buffer
  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: uuidv4

      Algorithm to use to generate the unique id

    Returns Buffer

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: uuidv1

      Algorithm to use to generate the unique id

    Returns Buffer

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: uuidv4String

      Algorithm to use to generate the unique id

    Returns string

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: uuidv1String

      Algorithm to use to generate the unique id

    Returns string

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: objectId

      Algorithm to use to generate the unique id

    Returns Buffer

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: nanoid

      Algorithm to use to generate the unique id

    • Optional size: number

    Returns string

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • idFormat: timestamp

      Algorithm to use to generate the unique id

    Returns number

  • Generates a unique ID using one of the available algorithms, returning the result as a Buffer, string or number.

    Parameters

    • Optional idFormat: IDFormat

      Algorithm to use to generate the unique id

    • Rest ...args: any[]

      Extra args to pass to the ID generation function

    Returns string | number | Buffer

Static arrayBufferToNodeBuffer

  • arrayBufferToNodeBuffer(arrayBuffer: any): Buffer
  • Encodes an ArrayBuffer to a node.js Buffer using npm:typedarray-to-buffer, and npm:Buffer if node.js Buffer is not available.

    Parameters

    • arrayBuffer: any

    Returns Buffer

Static ascii85ToNodeBuffer

  • ascii85ToNodeBuffer(base85: string): Buffer
  • Encodes a base64 string to a node.js buffer.

    Parameters

    • base85: string

    Returns Buffer

Static base32ToNodeBuffer

  • base32ToNodeBuffer(base32String: string, ...args: any[]): Buffer
  • Encodes a node.js buffer as a base32 string using npm:base32.js

    Parameters

    • base32String: string

      Base32 string to decode.

    • Rest ...args: any[]

      Additional arguments to be passed to the Decoder constructor in npm:base32.js

    Returns Buffer

Static base64ToNodeBuffer

  • base64ToNodeBuffer(base64: string): Buffer
  • Encodes a base64 string to a node.js buffer.

    Parameters

    • base64: string

    Returns Buffer

Static base64urlToNodeBuffer

  • base64urlToNodeBuffer(base64url: string): Buffer
  • Encodes a base64url string to a node.js buffer.

    author

    https://zb.gy/ESRN

    Parameters

    • base64url: string

    Returns Buffer

Static base85ToNodeBuffer

  • base85ToNodeBuffer(base85: string): Buffer
  • Encodes a base64 string to a node.js buffer.

    Parameters

    • base85: string

    Returns Buffer

Static bcrypt

  • Hashes using bcrypt

    Parameters

    Returns Promise<Buffer>

Static bcryptVerify

  • Compares a password with bcrypt

    Parameters

    Returns Promise<boolean>

Static bsonToObject

  • bsonToObject<T>(bson: Buffer): T
  • Deserializes a BSON encoded Buffer to an object

    Type parameters

    • T

    Parameters

    • bson: Buffer

      BSON to deserialize

    Returns T

Static cborToObject

  • cborToObject<T>(data: Buffer): T
  • Deserializes a CBOR-encoded Buffer to an object

    Type parameters

    • T

    Parameters

    • data: Buffer

      CBOR to deserialize

    Returns T

Static compressLZMA

  • compressLZMA(buf: Buffer, level: number): Promise<Buffer>
  • Compresses a buffer using LZMA

    Parameters

    • buf: Buffer

      Buffer

    • level: number

      Compression level (1-9)

    Returns Promise<Buffer>

Static compressZStd

  • compressZStd(buf: Buffer, level: number): Promise<Buffer>
  • Compresses a buffer using ZStd

    Parameters

    • buf: Buffer

      Buffer

    • level: number

      Compression level (1-9)

    Returns Promise<Buffer>

Static crc32

  • Parameters

    Returns Promise<Buffer>

Static create

  • Creates an an EncodeTools instance with the provided properties

    Parameters

    Returns default

Static createToPojoOptions

  • createToPojoOptions<I, O>(encoder: default, binaryEncoding?: BinaryEncoding, toPojoOptions?: ToPojoOptions<I, O>): { conversions: Conversion<unknown, unknown>[]; defaultTransform: TransformFn<unknown, unknown> }
  • Returns options for @thirdact/to-pojo with binary encoders set to the options in encode tools. This produces POJOs with, for example, buffers encoded as base64 or ``base85`

    Type parameters

    • I

    • O

    Parameters

    • encoder: default

      Encoder to use

    • Optional binaryEncoding: BinaryEncoding

      Binary encoding

    • Optional toPojoOptions: ToPojoOptions<I, O>

    Returns { conversions: Conversion<unknown, unknown>[]; defaultTransform: TransformFn<unknown, unknown> }

    • conversions: Conversion<unknown, unknown>[]
    • defaultTransform: TransformFn<unknown, unknown>

Static decodeSlugID

  • decodeSlugID(id: string): Buffer
  • Decodes a UUID encoded as a slugid returning the bytes as a Buffer

    Parameters

    • id: string

      SlugID encoded UUID

    Returns Buffer

Static decompressLZMA

  • decompressLZMA(buf: Buffer): Promise<Buffer>
  • Decompresses a buffer using LZMA

    Parameters

    • buf: Buffer

      Buffer

    Returns Promise<Buffer>

Static decompressZStd

  • decompressZStd(buf: Buffer): Promise<Buffer>
  • Decompresses a buffer using ZStd

    Parameters

    • buf: Buffer

      Buffer

    Returns Promise<Buffer>

Static encodeSlugID

  • encodeSlugID(uuid: Buffer): string
  • Decodes a UUID encoded as a slugid returning the bytes as a Buffer

    Parameters

    • uuid: Buffer

      UUID as a Buffer

    Returns string

Static ensureBuffer

  • Always returns the provided data as a Buffer, passing the data through Buffer.from if not already a Buffer

    author

    https://zb.gy/_wpj

    Parameters

    Returns Buffer

Static getImageMetadata

  • Gets metadata of the image provided as a buffer

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    Returns Promise<ImageMetadata>

  • Gets metadata of the image provided as a buffer

    Parameters

    • buffer: Buffer | ArrayBuffer

      Image

    Returns Promise<ImageMetadata>

  • Gets metadata of the image provided as a buffer

    Parameters

    Returns Promise<ImageMetadata>

Static getRandomBytes

  • getRandomBytes(n: number): Buffer
  • Gets random bytes returning the result as a Buffer

    Parameters

    • n: number

      Number of bytes to return

    Returns Buffer

Static hashidsToNodeBuffer

  • hashidsToNodeBuffer(hashid: string, ...args: any[]): Buffer
  • Decodes a hashids string, first to hex, then to a node.js buffer using npm:hashids.

    Parameters

    • hashid: string

      Hashid string to decode

    • Rest ...args: any[]

      Additional arguments to be passed to the Hashids constructor in npm:hashids

    Returns Buffer

Static hexToNodeBuffer

  • hexToNodeBuffer(hex: string): Buffer
  • Encodes a hexadecimal string to a node.js buffer.

    Parameters

    • hex: string

    Returns Buffer

Static json5ToObject

  • json5ToObject<T>(data: string | Buffer): T
  • Deserializes a JSON5 encoded string to an object

    Type parameters

    • T

    Parameters

    • data: string | Buffer

      JSON5 to deserialize

    Returns T

Static jsonToObject

  • jsonToObject<T>(data: string | Buffer): T
  • Deserializes a JSON encoded string to an object

    Type parameters

    • T

    Parameters

    • data: string | Buffer

      JSON to deserialize

    Returns T

Static md5

  • Uses the very popular, but VERY VERY UNSAFE, MD5 cryptographic algorithm. Use SHA3 for new projects.

    Uses MD5 from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Static msgpackToObject

  • msgpackToObject<T>(data: Buffer): T
  • Deserializes a msgpack encoded Buffer to an object

    Type parameters

    • T

    Parameters

    • data: Buffer

      msgpack to deserialize

    Returns T

Static nanoid

  • nanoid(size?: number): string
  • Generates an ID using nanoid

    Parameters

    • Optional size: number

      Size of the id (in characters)

    Returns string

Static newObjectId

  • newObjectId(): Buffer
  • Creates a new ObjectId returning the bytes as a Buffer

    Returns Buffer

Static nodeBufferToArrayBuffer

  • Encodes a node.js Buffer as an ArrayBuffer using npm:Buffer if node.js Buffer is not available.

    Parameters

    Returns ArrayBuffer

Static nodeBufferToAscii85

  • nodeBufferToAscii85(buffer: Buffer): string
  • Encodes a node.js buffer as a base64 string.

    Parameters

    • buffer: Buffer

    Returns string

Static nodeBufferToBase32

  • Encodes a node.js buffer as a base32 string using npm:base32.js

    Parameters

    • buffer: BinaryInputOutput

      Buffer to encode

    • Rest ...args: any[]

      Additional arguments to be passed to the Encoder constructor in npm:base32.js

    Returns string

Static nodeBufferToBase64

  • nodeBufferToBase64(buffer: Buffer): string
  • Encodes a node.js buffer as a base64 string.

    Parameters

    • buffer: Buffer

    Returns string

Static nodeBufferToBase64url

  • Encodes a node.js buffer as a base64url string.

    author

    https://zb.gy/ESRN

    Parameters

    Returns string

Static nodeBufferToBase85

  • nodeBufferToBase85(buffer: Buffer): string
  • Encodes a node.js buffer as a base64 string.

    Parameters

    • buffer: Buffer

    Returns string

Static nodeBufferToHashids

  • Encodes a hashids string, from a node.js buffer by first converting to hex and then using npm:hashids.

    Parameters

    • nodeBuffer: BinaryInputOutput
    • Rest ...args: any[]

      Additional arguments to be passed to the Hashids constructor in npm:hashids

    Returns string

Static nodeBufferToHex

  • nodeBufferToHex(buffer: Buffer): string
  • Encodes a node.js buffer as a hexadecimal string.

    Parameters

    • buffer: Buffer

    Returns string

Static objectToBson

  • objectToBson<T>(obj: T): Buffer
  • Serializes data as BSON, returning the result as a Buffer

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    Returns Buffer

Static objectToCbor

  • objectToCbor<T>(obj: T): Buffer
  • Serializes an object as a CBOR-encoded Buffer

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    Returns Buffer

Static objectToJson

  • objectToJson<T>(obj: T): string
  • Serializes data as a JSON encoded string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    Returns string

Static objectToJson5

  • objectToJson5<T>(obj: T): string
  • Serializes data as a JSON5 encoded string

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    Returns string

Static objectToMsgpack

  • objectToMsgpack<T>(obj: T): Buffer
  • Serializes data as msgpack, returning the result as a Buffer

    Type parameters

    • T

    Parameters

    • obj: T

      Object to serialize

    Returns Buffer

Static safeLoadModule

  • safeLoadModule(name: string): any
  • Attempts to load a module if available, or returns null

    author

    https://zb.gy/_wpj

    Parameters

    • name: string

    Returns any

Static sha1

  • Uses the very popular, but UNSAFE, SHA-1 cryptographic algorithm. Use SHA3 for new projects.

    Uses SHA1 from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Static sha2

  • Uses the popular, but UNSAFE, 512bit SHA-2 cryptographic algorithm. Use SHA3 for new projects.

    Uses 512bit SHA from npm:hash-wasm

    deprecated

    Use SHA512 instead

    Parameters

    Returns Promise<Buffer>

Static sha3

  • Uses the new SHA-3 cryptographic algorithm.

    Uses SHA-3 from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Static sha512

  • Uses the popular, but UNSAFE, 512bit SHA-2 cryptographic algorithm. Use SHA3 for new projects.

    Uses 512bit SHA from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Static timestamp

  • timestamp(): number
  • Returns a JavaScript timestamp (in milliseconds)

    Returns number

Static uuidv1

  • uuidv1(): Buffer
  • Generates a v1 UUID, returning the bytes as a Buffer

    Returns Buffer

Static Protected uuidv1Array

  • uuidv1Array(): number[]
  • Generates a v1 UUID, returning the bytes as an array of numbers

    Returns number[]

Static uuidv1String

  • uuidv1String(): string
  • Generates a v1 UUID, returning the bytes as a hexadecimal string in the traditional format (with dashes "-").

    Returns string

Static uuidv4

  • uuidv4(): Buffer
  • Generates a v4 UUID, returning the bytes as a Buffer

    Returns Buffer

Static Protected uuidv4Array

  • uuidv4Array(): number[]
  • Generates a v4 UUID, returning the bytes as an array of numbers

    Returns number[]

Static uuidv4String

  • uuidv4String(): string
  • Generates a v4 UUID, returning the bytes as a hexadecimal string in the traditional format (with dashes "-").

    Returns string

Static xxhash3

  • Hashes using XXHash-3 (https://zb.gy/l4kN), a fast, non-cryptographic, hashing function.

    Uses XXHash from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Static xxhash32

  • Hashes using XXHash-32 (https://zb.gy/l4kN), a fast, non-cryptographic, hashing function.

    Uses XXHash from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Static xxhash64

  • Hashes using XXHash-64 (https://zb.gy/l4kN), a fast, non-cryptographic, hashing function.

    Uses XXHash from npm:hash-wasm

    Parameters

    Returns Promise<Buffer>

Generated using TypeDoc