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.Long { Constructor.<Long> }
-
Long.js's Long class if available.
-
Decorator root (TypeScript).
Deprecated:
-
util.emptyArray constant{ *[] }
-
An immuable empty array.
-
util.emptyObject constant{ Object }
-
An immutable empty object.
-
Node's fs module if available.
-
util.global { Object }
-
Global object reference.
-
util.isNode { 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.nestingLimit { number }
-
Schema declaration nesting limit.
-
util.recursionLimit { number }
-
Recursion limit.
-
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
See:
Methods
-
util.asPromise(fn, ctx, params){ Promise<*> }
-
Returns a promise from a node-style callback function.
Parameters:
fnasPromiseCallback Function to call
ctx* Function context
params* repeatable Function arguments
Returns:
Promise.<*> Promisified function -
util.boolFromKey(key){ boolean }
-
Converts a boolean key to a boolean value.
Parameters:
keystring Map key
Returns:
boolean Boolean value -
Converts a string to camel case.
Parameters:
strstring String to convert
Returns:
string Converted string -
util.codegen(functionParams, functionName){ Codegen }
-
Begins generating a function.
Parameters:
functionParamsArray.<string> Function parameter names
functionNamestring optional Function name if not anonymous
Returns:
Codegen Appender that appends code to the function's body -
util.codegen(2)(functionName){ Codegen }
-
Begins generating a function.
Parameters:
functionNamestring optional Function name if not anonymous
Returns:
Codegen Appender that appends code to the function's body -
Compares reflected fields by id.
Parameters:
aField First field
bField Second field
Returns:
number Comparison value -
Decorator helper for enums (TypeScript).
Parameters:
objectObject Enum object
Deprecated:
Returns:
Enum Reflected enum -
Decorator helper for types (TypeScript).
Parameters:
ctorConstructor.<T> Constructor function
typeNamestring optional Type name, defaults to the constructor's name
Properties:
rootRoot Decorators root
Deprecated:
Returns:
Type Reflected type -
util.fetch(filename, options, callback){ undefined }
-
Fetches the contents of a file.
Parameters:
filenamestring File path or url
optionsIFetchOptions Fetch options
callbackFetchCallback Callback function
Returns:
undefined -
util.fetch(2)(path, callback){ undefined }
-
Fetches the contents of a file.
Parameters:
pathstring File path or url
callbackFetchCallback Callback function
Returns:
undefined -
util.fetch(3)(path, options){ Promise<(string|Uint8Array)> }
-
Fetches the contents of a file.
Parameters:
pathstring File path or url
optionsIFetchOptions optional Fetch options
Returns:
Promise.<(string|Uint8Array)> Promise -
util.inquire(moduleName){ Object }
-
Requires a module only if available.
Parameters:
moduleNamestring Module to require
Deprecated:
Returns:
Object Required module if available and not empty, otherwise null -
util.isInteger(value){ boolean }
-
Tests if the specified value is an integer.
Parameters:
value* Value to test
Returns:
boolean trueif the value is an integer -
util.isObject(value){ boolean }
-
Tests if the specified value is a non-null object.
Parameters:
value* Value to test
Returns:
boolean trueif the value is a non-null object -
Tests whether the specified name is a reserved word in JS.
Parameters:
namestring Name to test
Returns:
boolean trueif reserved, otherwisefalse -
util.isSet(obj, prop){ boolean }
-
Checks if a property on a message is considered to be present.
Parameters:
objObject Plain object or message instance
propstring Property name
Returns:
boolean trueif considered to be present, otherwisefalse -
util.isString(value){ boolean }
-
Tests if the specified value is a string.
Parameters:
value* Value to test
Returns:
boolean trueif the value is a string -
util.isset(obj, prop){ boolean }
-
Checks if a property on a message is considered to be present.
This is an alias of util.isSet.Parameters:
objObject Plain object or message instance
propstring Property name
Returns:
boolean trueif considered to be present, otherwisefalse -
util.lcFirst(str){ string }
-
Converts the first character of a string to lower case.
Parameters:
strstring String to convert
Returns:
string Converted string -
util.longFromHash(hash, unsigned){ Long | number }
-
Converts an 8 characters long hash string to a long or number.
Parameters:
hashstring Hash
unsignedboolean false optional Whether unsigned or not
Returns:
Long | number Original value -
util.longFromKey(key, unsigned){ Long | number | string }
-
Converts a 64 bit key to a long or number if it is an 8 characters long hash string.
Parameters:
keystring Map key
unsignedboolean false optional Whether unsigned or not
Returns:
Long | number | string Original value -
util.longToHash(value){ string }
-
Converts a number or long to an 8 characters long hash string.
Parameters:
valueLong | number Value to convert
Returns:
string Hash -
util.makeProp(obj, key, enumerable){ undefined }
-
Makes a property safe for assignment as an own property.
Parameters:
objObject.<string, *> Object
keystring Property key
enumerableboolean true optional Whether the property should be enumerable
Returns:
undefined -
util.merge(dst, src, ifNotSet){ Object<string, *> }
-
Merges the properties of the source object into the destination object.
Parameters:
dstObject.<string, *> Destination object
srcObject.<string, *> Source object
ifNotSetboolean false optional Merges only if the key is not already set
Returns:
Object.<string, *> Destination object -
util.newBuffer(sizeOrArray){ Uint8Array | Buffer }
-
Creates a new buffer of whatever type supported by the environment.
Parameters:
sizeOrArraynumber | Array.<number> 0 optional Buffer size or number array
Returns:
Uint8Array | Buffer Buffer -
util.newError(name){ Constructor.<Error> }
-
Creates a custom error constructor.
Parameters:
namestring Error name
Returns:
Constructor.<Error> Custom error constructor -
util.oneOfGetter(fieldNames){ OneOfGetter }
-
Builds a getter for a oneof's present field name.
Parameters:
fieldNamesArray.<string> Field names
Returns:
OneOfGetter Unbound getter -
util.oneOfSetter(fieldNames){ OneOfSetter }
-
Builds a setter for a oneof's present field name.
Parameters:
fieldNamesArray.<string> Field names
Returns:
OneOfSetter Unbound setter -
util.pool(alloc, slice, size){ PoolAllocator }
-
A general purpose buffer pool.
Parameters:
allocPoolAllocator Allocator
slicePoolSlicer Slicer
sizenumber 8192 optional Slab size
Returns:
PoolAllocator Pooled allocator -
Returns a safe property accessor for the specified property name.
Parameters:
propstring Property name
Returns:
string Safe accessor -
Sets the value of a property by property path. If a value already exists, it is turned to an array
Parameters:
dstObject.<string, *> Destination object
pathstring dot '.' delimited path of the property to set
valueObject the value to set
ifNotSetboolean | undefined optional Sets the option only if it isn't currently set
Returns:
Object.<string, *> Destination object -
Converts an object's values to an array.
Parameters:
objectObject.<string, *> Object to convert
Returns:
Array.<*> Converted array -
Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
Parameters:
arrayArray.<*> Array to convert
Returns:
Object.<string, *> Converted object -
Converts the first character of a string to upper case.
Parameters:
strstring String to convert
Returns:
string Converted string