Various utility functions.
Classes
Namespaces
Members
-
util.Array { Constructor.<Uint8Array> }
-
Array implementation used in the browser.
Uint8Arrayif supported, otherwiseArray. -
util.Buffer { Constructor.<Buffer> }
-
Node's Buffer class if available.
-
util.decorateRoot readonly{ Root }
-
Decorator root (TypeScript).
-
util.emptyArray constant{ *[] }
-
An immuable empty array.
-
util.emptyObject constant{ Object }
-
An immutable empty object.
-
util.fs { Object<string, *> }
-
Node's fs module if available.
-
util.isNode constant{ boolean }
-
Whether running within node or not.
-
util.key2Re constant{ RegExp }
-
Regular expression used to verify 2 bit (
bool) map keys. -
util.key32Re constant{ RegExp }
-
Regular expression used to verify 32 bit (
int32etc.) map keys. -
util.key64Re constant{ RegExp }
-
Regular expression used to verify 64 bit (
int64etc.) map keys. -
util.Long { Constructor.<Long> }
-
Long.js's Long class if available.
-
util.toJSONOptions { IConversionOptions }
-
Default conversion options used for Message#toJSON implementations.
These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
- Longs become strings
- Enums become string keys
- Bytes become base64 encoded strings
- (Sub-)Messages become plain objects
- Maps become plain objects with all string keys
- Repeated fields become arrays
- NaN and Infinity for float and double fields become strings
Methods
-
util.asPromise(fn, ctx, params){ Promise<*> }
-
Returns a promise from a node-style callback function.
Name Type Description fnasPromiseCallback Function to call
ctx* Function context
params* repeatable Function arguments
Returns:
Type Description Promise.<*> Promisified function -
util.camelCase(str){ string }
-
Converts a string to camel case.
Name Type Description strstring String to convert
Returns:
Type Description string Converted string -
util.codegen(functionParams, functionName){ Codegen }
-
Begins generating a function.
Name Type Description functionParamsArray.<string> Function parameter names
functionNamestring optional Function name if not anonymous
Returns:
Type Description Codegen Appender that appends code to the function's body -
util.codegen(2)(functionName){ Codegen }
-
Begins generating a function.
Name Type Description functionNamestring optional Function name if not anonymous
Returns:
Type Description Codegen Appender that appends code to the function's body -
util.compareFieldsById(a, b){ number }
-
Compares reflected fields by id.
Name Type Description aField First field
bField Second field
Returns:
Type Description number Comparison value -
util.decorateEnum(object){ Enum }
-
Decorator helper for enums (TypeScript).
Name Type Description objectObject Enum object
Returns:
Type Description Enum Reflected enum -
util.decorateType(ctor, typeName){ Type }
-
Decorator helper for types (TypeScript).
Name Type Description ctorConstructor.<T> Constructor function
typeNamestring optional Type name, defaults to the constructor's name
Properties:
Name Type Description rootRoot Decorators root
Returns:
Type Description Type Reflected type -
util.fetch(filename, options, callback){ undefined }
-
Fetches the contents of a file.
Name Type Description filenamestring File path or url
optionsIFetchOptions Fetch options
callbackFetchCallback Callback function
Returns:
Type Description undefined -
util.fetch(2)(path, callback){ undefined }
-
Fetches the contents of a file.
Name Type Description pathstring File path or url
callbackFetchCallback Callback function
Returns:
Type Description undefined -
util.fetch(3)(path, options){ Promise<(string|Uint8Array)> }
-
Fetches the contents of a file.
Name Type Description pathstring File path or url
optionsIFetchOptions optional Fetch options
Returns:
Type Description Promise.<(string|Uint8Array)> Promise -
util.inquire(moduleName){ Object }
-
Requires a module only if available.
Name Type Description moduleNamestring Module to require
Returns:
Type Description Object Required module if available and not empty, otherwise null -
util.isInteger(value){ boolean }
-
Tests if the specified value is an integer.
Name Type Description value* Value to test
Returns:
Type Description boolean trueif the value is an integer -
util.isObject(value){ boolean }
-
Tests if the specified value is a non-null object.
Name Type Description value* Value to test
Returns:
Type Description boolean trueif the value is a non-null object -
util.isReserved(name){ boolean }
-
Tests whether the specified name is a reserved word in JS.
Name Type Description namestring Name to test
Returns:
Type Description boolean trueif reserved, otherwisefalse -
util.isset(obj, prop){ boolean }
-
Checks if a property on a message is considered to be present.
This is an alias of util.isSet.Name Type Description objObject Plain object or message instance
propstring Property name
Returns:
Type Description boolean trueif considered to be present, otherwisefalse -
util.isSet(obj, prop){ boolean }
-
Checks if a property on a message is considered to be present.
Name Type Description objObject Plain object or message instance
propstring Property name
Returns:
Type Description boolean trueif considered to be present, otherwisefalse -
util.isString(value){ boolean }
-
Tests if the specified value is a string.
Name Type Description value* Value to test
Returns:
Type Description boolean trueif the value is a string -
util.lcFirst(str){ string }
-
Converts the first character of a string to lower case.
Name Type Description strstring String to convert
Returns:
Type Description string Converted string -
util.longFromHash(hash, unsigned){ Long | number }
-
Converts an 8 characters long hash string to a long or number.
Name Type Default Description hashstring Hash
unsignedboolean false optional Whether unsigned or not
Returns:
Type Description Long | number Original value -
util.longToHash(value){ string }
-
Converts a number or long to an 8 characters long hash string.
Name Type Description valueLong | number Value to convert
Returns:
Type Description string Hash -
util.merge(dst, src, ifNotSet){ Object<string, *> }
-
Merges the properties of the source object into the destination object.
Name Type Default Description dstObject.<string, *> Destination object
srcObject.<string, *> Source object
ifNotSetboolean false optional Merges only if the key is not already set
Returns:
Type Description Object.<string, *> Destination object -
util.newBuffer(sizeOrArray){ Uint8Array | Buffer }
-
Creates a new buffer of whatever type supported by the environment.
Name Type Default Description sizeOrArraynumber | Array.<number> 0 optional Buffer size or number array
Returns:
Type Description Uint8Array | Buffer Buffer -
util.newError(name){ Constructor.<Error> }
-
Creates a custom error constructor.
Name Type Description namestring Error name
Returns:
Type Description Constructor.<Error> Custom error constructor -
util.oneOfGetter(fieldNames){ OneOfGetter }
-
Builds a getter for a oneof's present field name.
Name Type Description fieldNamesArray.<string> Field names
Returns:
Type Description OneOfGetter Unbound getter -
util.oneOfSetter(fieldNames){ OneOfSetter }
-
Builds a setter for a oneof's present field name.
Name Type Description fieldNamesArray.<string> Field names
Returns:
Type Description OneOfSetter Unbound setter -
util.pool(alloc, slice, size){ PoolAllocator }
-
A general purpose buffer pool.
Name Type Default Description allocPoolAllocator Allocator
slicePoolSlicer Slicer
sizenumber 8192 optional Slab size
Returns:
Type Description PoolAllocator Pooled allocator -
util.safeProp(prop){ string }
-
Returns a safe property accessor for the specified property name.
Name Type Description propstring Property name
Returns:
Type Description string Safe accessor -
util.toArray(object){ *[] }
-
Converts an object's values to an array.
Name Type Description objectObject.<string, *> Object to convert
Returns:
Type Description Array.<*> Converted array -
util.toObject(array){ Object<string, *> }
-
Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
Name Type Description arrayArray.<*> Array to convert
Returns:
Type Description Object.<string, *> Converted object -
util.ucFirst(str){ string }
-
Converts the first character of a string to upper case.
Name Type Description strstring String to convert
Returns:
Type Description string Converted string