A module with functions that perform runtime type checks. There are very simple checks such
as isString()
, there also are complex checks.
- Source:
Methods
(static) countEnumerableProperties(o) → {number}
Parameters:
Name | Type | Description |
---|---|---|
o |
object |
An alternative to Object.keys(o).length
that is more efficient. Running a test loop
comparing the two showed less than half the time for the for-loop option. Also, Object.keys
creates a temporary array.
- Source:
Returns:
Type: number
(static) isEncoding(thing) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
Valid encodings for file streams are binary (undefined or null), "base64" and "utf8".
- Source:
Returns:
Type: boolean
(static) isHash(thing) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* | An argument that can be of any type |
ONE uses SHA-256 hashes in hexadecimal lowercase format to represent the contents of files. This functions tests a given "thing" of any type if it is such a string.
For the curious: Why a function?
While one might simply test against a regular expression using myRegEx.test(thing) this method has one more or less theoretical problem: If the thing is an object with a toString() method that returns a matching string the test will return "true" even though the thing is an object and not a string. For example,
/^s+$/.test( {toString: () => 'sss'} );
will return true.
- Source:
Returns:
True if the argument is a SHA-256 lowercase hexadecimal string, false if not
Type: boolean
(static) looksLikeHash(s) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
s |
* |
Non-regex version of the "isHash" function in an attempt to save a tiny bit of CPU because we don't need a full regex check here. "Premature optimization" vs. "it's cheap and easy", and according to reported real world runtime experience these hash checks can add up and become significant.
- Source:
Returns:
Type: boolean
(static) ensureHash(thing) → {SHA256Hash}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
The function returns the given value after making sure it is a SHA-256 hexadecimal string. It throws an Error if this is not the case.
- Source:
Throws:
Returns:
Type: SHA256Hash
(static) ensureIdHash(thing) → {SHA256Hash}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
The function returns the given value after making sure it is a SHA-256 hexadecimal string. It throws an Error if this is not the case.
- Source:
Throws:
Returns:
Type: SHA256Hash
(static) isEventSourceConsumer(thing) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
Checks if a given object is a ONE.core OneEventSourceConsumer object by testing the properties (duck typing).
- Source:
Returns:
Type: boolean
(static) isEventSource(thing) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
Checks if a given object is a ONE.core OneEventSource object by testing the properties (duck typing).
- Source:
Returns:
Type: boolean
(static) isSimpleReadStream(thing) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
Checks if a given object is a ONE.core SimpleReadStream object by testing the properties (duck typing).
- Source:
Returns:
Type: boolean
(static) isFileCreationResult(thing) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* |
Checks for FileCreation objects. They are used to return the result of saving BLOBs and CLOBs to storage.
- Source:
Returns:
Type: boolean
(static) ensureArrayOfSHA256Hash(thing) → {Array.<SHA256Hash>}
Parameters:
Name | Type | Description |
---|---|---|
thing |
* | Data e.g. from a network connection expected to be of format SHA256Hash[] |
- Source:
Throws:
-
Throws an Error when the given data is not an array of (only) SHA-256 hashes
-
Type: Error
Returns:
Returns the data now confirmed to be of type Array of SHA256Hash
Type: Array.<SHA256Hash>
(static) ruleHasItemType(obj) → {RecipeRule}
Parameters:
Name | Type | Description |
---|---|---|
obj |
RecipeRule |
- Source:
Returns:
Type: RecipeRule
(static) isListItemType(arg) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
arg |
ValueType |
Check if the valueType is a list type: array, bag, or set.
- Source:
Returns:
Type: boolean