@vapaaradikaali/helpers.js v0.41.3
Modules
Classes
Functions
Errors
Errors~ConfigError
Kind: inner class of Errors Summary: Config error.
new ConfigError()
Errors~ConfigNotFoundError ⇐ ConfigError
Kind: inner class of Errors Summary: Config not found error. Extends: ConfigError
new ConfigNotFoundError()
Errors~ConfigParseError ⇐ ConfigError
Kind: inner class of Errors Summary: Config parse error. Extends: ConfigError
new ConfigParseError()
BrowserEvents
Kind: global class Summary: Browser events class.
new BrowserEvents()
browserEvents.on(eventName, callback)
Kind: instance method of BrowserEvents Summary: Register an event listener.
Param | Type | Description |
---|---|---|
eventName | string | Event name |
callback | function | Event listener |
browserEvents.off(eventName, callback)
Kind: instance method of BrowserEvents Summary: Unregister event listeners, optionally only the given.
Param | Type | Description |
---|---|---|
eventName | string | Event name |
callback | function | Event listener |
browserEvents.trigger(eventName)
Kind: instance method of BrowserEvents Summary: Trigger an event.
Param | Type | Description |
---|---|---|
eventName | string | Event name |
...args | mixed | Event arguments |
Config
Kind: global class Summary: Configuration class.
- Config
- new Config()
- .constructor([values], [schema])
- .setDefaultValues() ⇒ Config
- .getValidator() ⇒ jsonschema.Validator
- .getPath(path) ⇒ array
- .set([path], value) ⇒ Config
- .del([path])
- .validateBeforeSet([path], value) ⇒ Config
- .validate([values], [schema]) ⇒ Config
- .setValuesToPath([path], value, target) ⇒ object
- .get(paths, defaultValue) ⇒ mixed
- .toJSON() ⇒ object
new Config()
config.constructor(values, schema)
Kind: instance method of Config Summary: Constructor.
Param | Type | Description |
---|---|---|
values | object | Instance values |
schema | object | Instance schema |
config.setDefaultValues() ⇒ Config
Kind: instance method of Config Summary: Set default values. Returns: Config - Self
config.getValidator() ⇒ jsonschema.Validator
Kind: instance method of Config Summary: Get a singleton instance of validator. Returns: jsonschema.Validator - Validator instance
config.getPath(path) ⇒ array
Kind: instance method of Config Summary: Internal helper to get path from the given argument. Returns: array - Path as an array
Param | Type | Description |
---|---|---|
path | mixed | String or an array of strings |
config.set(path, value) ⇒ Config
Kind: instance method of Config Summary: Set configuration value. Returns: Config - Self
Param | Type | Description |
---|---|---|
path | string | Array.<string> | or an array of strings |
value | mixed | Any value that can be serialized as JSON |
config.del(path)
Kind: instance method of Config Summary: Delete a configuration value.
Param | Type | Description |
---|---|---|
path | string | Array.<string> | or an array of strings |
config.validateBeforeSet(path, value) ⇒ Config
Kind: instance method of Config Summary: Validate the value before setting it. Returns: Config - Self
Param | Type | Description |
---|---|---|
path | string | Array.<string> | or an array of strings |
value | mixed | Any value that can be serialized as JSON |
config.validate(values, schema) ⇒ Config
Kind: instance method of Config Summary: Validate configuration. Returns: Config - Self
Param | Type | Description |
---|---|---|
values | object | Values; stored values when omitted |
schema | object | Schema to validate against |
config.setValuesToPath(path, value, target) ⇒ object
Kind: instance method of Config Summary: Set value to path for the given target object. Returns: object - Target object
Param | Type | Description |
---|---|---|
path | string | Array.<string> | or an array of strings |
value | mixed | Any value that can be serialized as JSON |
target | object | Target object |
config.get(paths, defaultValue) ⇒ mixed
Kind: instance method of Config Summary: Get configuration value. Returns: mixed - Stored configuration value or the given default value
Param | Type | Description |
---|---|---|
paths | string | Array.<string> | String or an array of strings |
defaultValue | mixed | Default value if the stored is null or undefined |
config.toJSON() ⇒ object
Kind: instance method of Config Summary: JSON serializer. Returns: object - JSON serializeable object
Datamap
Kind: global class Summary: Replacement for Javascript's native Map that is very slow to access data versus a purecode object.
- Datamap
- new Datamap()
- instance
- .length : number
- .size : number
- .clone : function
- .has(key) ⇒ boolean
- .get(key) ⇒ mixed
- .set(key, value)
- .add(value)
- .setIndex(index)
- .keys() ⇒ Array.<string>
- .values() ⇒ Array.<mixed>
- .clear()
- .delete(key)
- .forEach(iterator)
- .map(iterator) ⇒ Array.<mixed>
- .reduce(iterator, initialValue) ⇒ mixed
- .filter(iterator) ⇒ Datamap
- .copy() ⇒ Datamap
- .slice([start], [end]) ⇒ Datamap
- static
new Datamap()
datamap.length : number
Kind: instance constant of Datamap Summary: Datamap length.
datamap.size : number
Kind: instance constant of Datamap Summary: Datamap size, alias to length.
datamap.clone : function
Kind: instance constant of Datamap Summary: Clone a datamap, alias for copy.
datamap.has(key) ⇒ boolean
Kind: instance method of Datamap Summary: Check if the datamap has the given key. Returns: boolean - True if a value exists
Param | Type | Description |
---|---|---|
key | mixed | Map key |
datamap.get(key) ⇒ mixed
Kind: instance method of Datamap Summary: Get the datamap value. Returns: mixed - Stored value
Param | Type | Description |
---|---|---|
key | mixed | Map key |
datamap.set(key, value)
Kind: instance method of Datamap Summary: Set the datamap value.
Param | Type | Description |
---|---|---|
key | mixed | Map key |
value | mixed | Stored value |
datamap.add(value)
Kind: instance method of Datamap Summary: Add an indexed datamap value.
Param | Type | Description |
---|---|---|
value | object | Any value |
datamap.setIndex(index)
Kind: instance method of Datamap Summary: Set index for datamap values.
Param | Type | Description |
---|---|---|
index | string | Any value |
datamap.keys() ⇒ Array.<string>
Kind: instance method of Datamap Summary: Get the datamap keys. Returns: Array.<string> - Stored keys
datamap.values() ⇒ Array.<mixed>
Kind: instance method of Datamap Summary: Get the datamap values. Returns: Array.<mixed> - Stored values
datamap.clear()
Kind: instance method of Datamap Summary: Clear the datamap.
datamap.delete(key)
Kind: instance method of Datamap Summary: Delete a datamap key.
Param | Type | Description |
---|---|---|
key | mixed | Map key |
datamap.forEach(iterator)
Kind: instance method of Datamap Summary: Iterate a datamap.
Param | Type | Description |
---|---|---|
iterator | function | Iterator callback function |
datamap.map(iterator) ⇒ Array.<mixed>
Kind: instance method of Datamap Summary: Map function for a datamap. Returns: Array.<mixed> - Iterator output
Param | Type | Description |
---|---|---|
iterator | function | Iterator callback function |
datamap.reduce(iterator, initialValue) ⇒ mixed
Kind: instance method of Datamap Summary: Reduce function for a datamap. Returns: mixed - Iterator output
Param | Type | Description |
---|---|---|
iterator | function | Iterator callback function |
initialValue | mixed | Initial value |
datamap.filter(iterator) ⇒ Datamap
Kind: instance method of Datamap Summary: Filter function for Datamap. Returns: Datamap - Filtered datamap
Param | Type | Description |
---|---|---|
iterator | function | Iterator callback function |
datamap.copy() ⇒ Datamap
Kind: instance method of Datamap Summary: Copy function for datamap. Returns: Datamap - Copy of the datamap
datamap.slice(start, end) ⇒ Datamap
Kind: instance method of Datamap Summary: Slice function for datamap. Returns: Datamap - Sliced copy of the datamap
Param | Type | Description |
---|---|---|
start | number | Start index |
end | number | End index |
Datamap.Options : Options
Kind: static constant of Datamap Summary: Options object for Datamaps.
Dataset
Kind: global class Summary: Dataset. Implements: Set
- Dataset
- new Dataset([data], [options])
- .size
- .includes
- .contains
- .clear
- .*iterator()
- .toArray() ⇒
- .addToMap(values) ⇒ Dataset
- .add(values)
- .addToIndices(values) ⇒ Dataset
- .copy() ⇒ Dataset
- .merge(data) ⇒ Dataset
- .concat()
- .delete(values)
- .clear()
- .getById(id) ⇒ mixed
- .getByIndex(index, id) ⇒ mixed
- .getByProperty(prop, value, recursive)
- .map(iterator) ⇒ Dataset
- .filetr(iterator, matchAny) ⇒ Array.<mixed>
- .reduce(reducer, initial) ⇒ mixed
- .sort(callback) ⇒ Dataset
- .reverse() ⇒ Dataset
- .find(callback) ⇒ mixed
- .findLast(callback) ⇒ mixed
- .toJSON() ⇒ array
- .splitIntoChunks(length) ⇒ Array.<Dataset>
new Dataset(data, options)
Param | Type | Description |
---|---|---|
data | Array | Set | Initial data |
options | object | Options |
dataset.size
Kind: instance property of Dataset Summary: Alias "length" for "size".
dataset.includes
Kind: instance property of Dataset Summary: Alias "includes" for "has".
dataset.contains
Kind: instance property of Dataset Summary: Alias "contains" for has.
dataset.clear
Kind: instance property of Dataset Summary: Alias "truncate" for "clear".
dataset.*iterator()
Kind: instance method of Dataset Summary: Iterator protocol.
dataset.toArray() ⇒
Kind: instance method of Dataset Summary: Convert dataset to an array. Returns: Array
dataset.addToMap(values) ⇒ Dataset
Kind: instance method of Dataset Summary: Add values to map. Returns: Dataset - This instance
Param | Type | Description |
---|---|---|
values | mixed | An individual value, an array or a Set |
dataset.add(values)
Kind: instance method of Dataset Summary: Add an item.
Param | Type | Description |
---|---|---|
values | Array.<mixed> | Any value |
dataset.addToIndices(values) ⇒ Dataset
Kind: instance method of Dataset Summary: Add values to indices. Returns: Dataset - This instance
Param | Type | Description |
---|---|---|
values | mixed | An individual value, an array or a Set |
dataset.copy() ⇒ Dataset
Kind: instance method of Dataset Summary: Copy the current dataset. Returns: Dataset - Copy of this instance
dataset.merge(data) ⇒ Dataset
Kind: instance method of Dataset Summary: Merge datasets. Returns: Dataset - Merged datasets
Param | Type | Description |
---|---|---|
data | Array.<Dataset> | Datasets to merge |
dataset.concat()
Kind: instance method of Dataset Summary: Alias for merge.
dataset.delete(values)
Kind: instance method of Dataset Summary: Delete an item.
Param | Type | Description |
---|---|---|
values | Array.<mixed> | Any value |
dataset.clear()
Kind: instance method of Dataset Summary: Clear the dataset.
dataset.getById(id) ⇒ mixed
Kind: instance method of Dataset Summary: Get item by id. Returns: mixed - Stored value
Param | Type | Description |
---|---|---|
id | number | string | Value of the id property |
dataset.getByIndex(index, id) ⇒ mixed
Kind: instance method of Dataset Summary: Get item by indexed value. Returns: mixed - Stored value
Param | Type | Description |
---|---|---|
index | string | Index |
id | number | string | Value of the id property |
dataset.getByProperty(prop, value, recursive)
Kind: instance method of Dataset Summary: Get by property.
Param | Type | Description |
---|---|---|
prop | string | Property |
value | mixed | Needle |
recursive | string | Recursive property |
dataset.map(iterator) ⇒ Dataset
Kind: instance method of Dataset Summary: Map like an array map. Returns: Dataset - Dataset of the values returned by the iterator
Param | Type | Description |
---|---|---|
iterator | function | Iterator function |
dataset.filetr(iterator, matchAny) ⇒ Array.<mixed>
Kind: instance method of Dataset Summary: Filter like an array filter. Returns: Array.<mixed> - An array with the value iterator gives
Param | Type | Description |
---|---|---|
iterator | function | object | Iterator function or an object filter |
matchAny | boolean | Match any flag |
dataset.reduce(reducer, initial) ⇒ mixed
Kind: instance method of Dataset Summary: Reduce the dataset. Returns: mixed - Reduced value
Param | Type | Description |
---|---|---|
reducer | function | Reducer function |
initial | mixed | Initial value |
dataset.sort(callback) ⇒ Dataset
Kind: instance method of Dataset Summary: Sort a dataset. Returns: Dataset - Sorted dataset
Param | Type | Description |
---|---|---|
callback | function | Sort callback |
dataset.reverse() ⇒ Dataset
Kind: instance method of Dataset Summary: Reverse a dataset. Returns: Dataset - Reversed dataset
dataset.find(callback) ⇒ mixed
Kind: instance method of Dataset Summary: Find the first occurence from a dataset. Returns: mixed - Dataset item
Param | Type | Description |
---|---|---|
callback | function | Find callback |
dataset.findLast(callback) ⇒ mixed
Kind: instance method of Dataset Summary: Find the last occurence from a dataset. Returns: mixed - Dataset item
Param | Type | Description |
---|---|---|
callback | function | Find callback |
dataset.toJSON() ⇒ array
Kind: instance method of Dataset Summary: Serialize dataset as JSON. Returns: array - JSON serializable array
dataset.splitIntoChunks(length) ⇒ Array.<Dataset>
Kind: instance method of Dataset Summary: Split the dataset into chunks. Returns: Array.<Dataset> - An array of datasets
Param | Type | Description |
---|---|---|
length | number | Number of chunks |
LocalizationError
Kind: global class Summary: Localization error.
new LocalizationError()
InvalidTimestamp
Kind: global class Summary: Invalid timestamp error.
new InvalidTimestamp()
InvalidFormatter
Kind: global class Summary: Invalid formatter error.
new InvalidFormatter()
Localization
Kind: global class Summary: Localization class.
- Localization
- new Localization([lang], [fallbackLang])
- instance
- .errors : object
- .registerLogger(logger) ⇒ Localization
- .logger(level, args) ⇒ Localization
- .registerLocale() ⇒ function
- .registerLocales() ⇒ function
- .getLocales([lang]) ⇒ object
- .unregisterLocales() ⇒ function
- .unregisterLocale() ⇒ function
- .toCase() ⇒ function
- static
- .UPPERCASE : string
- .LOWERCASE : string
- .TITLECASE : string
- .PARAGRAPHCASE : string
- .CAMELCASE : string
- .UNDERSCORECASE : string
- .INVALID_TIMESTAMP : Errors.InvalidTimestamp
- .errors : object
- .validateRounding(rounding)
- .getRoundedNumber(value, [precision], [rounding]) ⇒ number
- .toCase(input, toCase) ⇒ string
- .registerLogger(logger)
- .registerLocale(locale, translations) ⇒ Localization
- .registerLocales(data) ⇒ Localization
- .getLocales([lang]) ⇒ object
- .unregisterLocales(data) ⇒ Localization
- .unregisterLocale() ⇒ function
new Localization(lang, fallbackLang)
Param | Type | Description |
---|---|---|
lang | string | Localization language |
fallbackLang | string | Fallback language if the main language is not found |
Example
`const l10n = new Localization('fi', 'en')`
localization.errors : object
Kind: instance constant of Localization Summary: Errors wrapper.
localization.registerLogger(logger) ⇒ Localization
Kind: instance method of Localization Summary: Shorthand for the static method Localization.registerLogger. Returns: Localization - This instance
Param | Type | Description |
---|---|---|
logger | function | Callback function |
localization.logger(level, args) ⇒ Localization
Kind: instance method of Localization Summary: Call logger. Returns: Localization - This instance
Param | Type | Description |
---|---|---|
level | number | Log level |
args | array | Logger arguments |
localization.registerLocale() ⇒ function
Kind: instance method of Localization Summary: Alias to the static registerLocale method. Returns: function - Constructor.toCase function
localization.registerLocales() ⇒ function
Kind: instance method of Localization Summary: Alias to the static registerLocales method. Returns: function - Constructor.toCase function
localization.getLocales(lang) ⇒ object
Kind: instance method of Localization Summary: Get locales, an instance convenience alias for the static method Localization.getLocales. Returns: object - Registered locales
Param | Type | Description |
---|---|---|
lang | string | Language constraint |
localization.unregisterLocales() ⇒ function
Kind: instance method of Localization Summary: Alias to the static registerLocales method. Returns: function - Constructor.toCase function
localization.unregisterLocale() ⇒ function
Kind: instance method of Localization Summary: Alias to the static registerLocales method. Returns: function - Constructor.toCase function
localization.toCase() ⇒ function
Kind: instance method of Localization Summary: Alias to the static toCase method. Returns: function - Constructor.toCase function
Localization.UPPERCASE : string
Kind: static constant of Localization
Localization.LOWERCASE : string
Kind: static constant of Localization
Localization.TITLECASE : string
Kind: static constant of Localization
Localization.PARAGRAPHCASE : string
Kind: static constant of Localization
Localization.CAMELCASE : string
Kind: static constant of Localization
Localization.UNDERSCORECASE : string
Kind: static constant of Localization
Localization.INVALID_TIMESTAMP : Errors.InvalidTimestamp
Kind: static constant of Localization
Localization.errors : object
Kind: static constant of Localization Summary: Static errros wrapper.
Localization.validateRounding(rounding)
Kind: static method of Localization Summary: Validate rounding type.
Param | Type | Description |
---|---|---|
rounding | string | Enumerates "round", "ceil", "floor" |
Localization.getRoundedNumber(value, precision, rounding) ⇒ number
Kind: static method of Localization Summary: Get rounded number. Returns: number - Rounded number
Param | Type | Default | Description |
---|---|---|---|
value | number | string | Number or a numeric string to round | |
precision | number | Rounding precision | |
rounding | string | "\"round\"" | Enumerates "round", "ceil", "floor" |
Localization.toCase(input, toCase) ⇒ string
Kind: static method of Localization Summary: Convert case for a string. Returns: string - String converted to the given case
Param | Type | Description |
---|---|---|
input | string | Input string |
toCase | string | Case for the output |
Localization.registerLogger(logger)
Kind: static method of Localization Summary: Register a logger for the localization.
Param | Type | Description |
---|---|---|
logger | function | Callback function |
Example
Localization.registerLogger((...args) => console.log(...args))
Localization.registerLocale(locale, translations) ⇒ Localization
Kind: static method of Localization Summary: Register locales. Returns: Localization - This instance
Param | Type | Description |
---|---|---|
locale | string | Locale key |
translations | object | Translations |
Localization.registerLocales(data) ⇒ Localization
Kind: static method of Localization Summary: Register locales. Returns: Localization - This instance
Param | Type | Description |
---|---|---|
data | object | Locales to register |
Localization.getLocales(lang) ⇒ object
Kind: static method of Localization Summary: Get locales. Returns: object - Registered locales
Param | Type | Description |
---|---|---|
lang | string | Language constraint |
Localization.unregisterLocales(data) ⇒ Localization
Kind: static method of Localization Summary: Unregister locales. Returns: Localization - This instance
Param | Type | Description |
---|---|---|
data | mixed | Locales to be registered as a string or array of strings |
Localization.unregisterLocale() ⇒ function
Kind: static method of Localization Summary: Alias to the static registerLocales method. Returns: function - Constructor.toCase function
Storage
Kind: global class Summary: Storage class.
- Storage
- new Storage(engine)
- instance
- static
- .StorageEngine : StorageEngine
- .validateKey(key)
- .getExpiresAt(expiresAt) ⇒ undefined | Moment
- .hasExpired(expiresAt) ⇒ boolean
new Storage(engine)
Param | Type | Description |
---|---|---|
engine | mixed | Storage engine |
storage.setEngines(engine)
Kind: instance method of Storage Summary: Set storage engine.
Param | Type | Description |
---|---|---|
engine | mixed | Storage engine |
storage.set(key, value, expiresAt)
Kind: instance method of Storage Summary: Set stored value.
Param | Type | Description |
---|---|---|
key | string | Storage key |
value | mixed | Storage value |
expiresAt | mixed | ISO 8601 temporal, seconds as number or anything Moment.js accepts |
storage.get(key, defaultValue) ⇒
Kind: instance method of Storage Summary: Get stored value. Returns: mixed Stored value, default value or null
Param | Type | Description |
---|---|---|
key | string | Storage key |
defaultValue | mixed | Value if storage does not have anything |
storage.del(key)
Kind: instance method of Storage Summary: Delete a storage key.
Param | Type | Description |
---|---|---|
key | string | Storage key |
storage.clear()
Kind: instance method of Storage Summary: Clear storage.
Storage.StorageEngine : StorageEngine
Kind: static constant of Storage Summary: Storage engine.
Storage.validateKey(key)
Kind: static method of Storage Summary: Validate storage key.
Param | Type | Description |
---|---|---|
key | string | Storage key |
Storage.getExpiresAt(expiresAt) ⇒ undefined | Moment
Kind: static method of Storage Summary: Get expires at. Returns: undefined | Moment - Undefined when no expiration is given, an instance of Moment otherwise
Param | Type | Description |
---|---|---|
expiresAt | mixed | ISO 8601 temporal, seconds as number or anything Moment.js accepts |
Storage.hasExpired(expiresAt) ⇒ boolean
Kind: static method of Storage Summary: Check if the timestamp is in the past. Returns: boolean - True if expired, otherwise false
Param | Type | Description |
---|---|---|
expiresAt | string | Expiration timestamp as ISO 8601 string |
TreeError
Kind: global class Summary: Tree error baseclass. Implements: Error
new TreeError()
PropertyError
Kind: global class Summary: PropertyError. Implements: TreeError
new PropertyError()
new PropertyError()
PropertyError
Kind: global class Summary: InvalidArgument. Implements: TreeError
new PropertyError()
new PropertyError()
NodeNotFound
Kind: global class Summary: NodeNotFound. Implements: TreeError
new NodeNotFound()
Tree
Kind: global class Summary: Tree traversal class.
- Tree
- new Tree([items], [idProperty], [parentProperty])
- instance
- .addNode() ⇒ Tree
- .addNodes(items) ⇒ Tree
- .getNode(needle) ⇒ Node
- .getBranch(needle, [metadata]) ⇒ Array.<object>
- .getParents(needle, [metadata]) ⇒ Array.<object>
- .getParents(needle, [metadata]) ⇒ object
- .getParents([needle], [metadata]) ⇒ object
- .isInTree(needle, haystack, [metadata]) ⇒ boolean
- .getItems([metadata])
- .removeItem(needle)
- .removeItems([needles])
- .removeItems([needles])
- static
- .errors
- .DEFAULT_ID_PROPERTY : string
- .DEFAULT_PARENT_PROPERTY : string
new Tree(items, idProperty, parentProperty)
Param | Type | Default | Description |
---|---|---|---|
items | Array.<object> | Items | |
idProperty | string | "'id'" | Attribute used for identifier |
parentProperty | string | "'parent'" | Attribute used for parent |
Example
const nodes = [
{
attr_id: 1,
attr_parent: null
},
{
attr_id: 11,
attr_parent: 1
},
{
attr_id: 12,
attr_parent: 1
},
{
attr_id: 2,
attr_parent: null
}
]
const tree = new Tree(nodes, 'attr_id', 'attr_parent)
tree.addNode() ⇒ Tree
Kind: instance method of Tree Summary: An alias to addNodes. Returns: Tree - This instance
tree.addNodes(items) ⇒ Tree
Kind: instance method of Tree Summary: Add nodes to the tree. Returns: Tree - This instance
Param | Type | Description |
---|---|---|
items | object | Array.<object> | Nodes to add |
tree.getNode(needle) ⇒ Node
Kind: instance method of Tree Summary: Get node. Returns: Node - Matching node
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
tree.getBranch(needle, metadata) ⇒ Array.<object>
Kind: instance method of Tree Summary: Get branch starting from the given node. Returns: Array.<object> - Original items of the branch
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
metadata | boolean | Flag to define if the function should return Nodes instead of original objects |
tree.getParents(needle, metadata) ⇒ Array.<object>
Kind: instance method of Tree Summary: Get branch starting from the given node. Returns: Array.<object> - Original items of the parent tree
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
metadata | boolean | Flag to define if the function should return Nodes instead of original objects |
tree.getParents(needle, metadata) ⇒ object
Kind: instance method of Tree Summary: Get root node for the given needle. Returns: object - Original items of the parent tree
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
metadata | boolean | Flag to define if the function should return Nodes instead of original objects |
tree.getParents(needle, metadata) ⇒ object
Kind: instance method of Tree Summary: Get leaves or the outmost part of the branch for the given needle. Returns: object - Original items of the parent tree
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
metadata | boolean | Flag to define if the function should return Nodes instead of original objects |
tree.isInTree(needle, haystack, metadata) ⇒ boolean
Kind: instance method of Tree Summary: Get branch starting from the given node. Returns: boolean - True if in the same tree, false if not
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
haystack | mixed | Haystrack to search |
metadata | boolean | Flag to define if the function should return Nodes instead of original objects |
tree.getItems(metadata)
Kind: instance method of Tree Summary: Get tree contents.
Param | Type | Description |
---|---|---|
metadata | boolean | Flag to define if the function should return Nodes instead of original objects |
tree.removeItem(needle)
Kind: instance method of Tree Summary: Remove an item.
Param | Type | Description |
---|---|---|
needle | mixed | Needle to search |
tree.removeItems(needles)
Kind: instance method of Tree Summary: Remove multiple items or flush the whole tree if no needle is provided.
Param | Type | Description |
---|---|---|
needles | mixed | Needles to search |
tree.removeItems(needles)
Kind: instance method of Tree Summary: Flush the whole tree.
Param | Type | Description |
---|---|---|
needles | mixed | Needles to search |
Tree.errors
Kind: static constant of Tree Summary: Errors.
Tree.DEFAULT_ID_PROPERTY : string
Kind: static constant of Tree Summary: Default id property. Default: "id"
Tree.DEFAULT_PARENT_PROPERTY : string
Kind: static constant of Tree Summary: Default parent property. Default: "parent"
setSchema(schema) ⇒ Config
Kind: global function Summary: Set JSON schema validation for the configuration. Returns: Config - Self
Param | Type | Description |
---|---|---|
schema | object | JSON schema |
addSchema(schema) ⇒ Config
Kind: global function Summary: Add a JSON schema to config validator. Returns: Config - Self
Param | Type | Description |
---|---|---|
schema | object | JSON schema |
normalizeSchemaId(id) ⇒ string
Kind: global function Summary: Normalize schema id. Returns: string - Normalized schema id
Param | Type | Description |
---|---|---|
id | string | Schema ID |
buildUrl(args)
Kind: global function Summary: Build URL from the given parameters.
Param | Type | Description |
---|---|---|
args | string | Array.<string> | Arguments |
Example
`buildUrl('postgresql', 'localhost', null, 'postgres', 'databaseName', { keepAlive: false })` returns `postgresql://postgres@localhost/databaseName?keepAlive=false`
buildUrl(protocol, host, port, username, password, location, query) ⇒ string
Kind: global function Summary: Build URL from the given parameters. Returns: string - Constructed URL
Param | Type | Description |
---|---|---|
protocol | string | object | Protocol or full configuration |
host | string | Host name |
port | number | Port |
username | string | Username |
password | string | Password |
location | string | Location |
query | object | Query parameters |
Example
`buildUrl('postgresql', 'localhost', null, 'postgres', 'databaseName', { keepAlive: false })` returns `postgresql://postgres@localhost/databaseName?keepAlive=false`
castObjectAsArray(source, recurse) ⇒ array
Kind: global function Summary: Cast an indexed object as array. Returns: array - Array conversion of the object
Param | Type | Description |
---|---|---|
source | object | Source object |
recurse | boolean | Recurse to child objects |
castToArray(input) ⇒ mixed
Kind: global function Summary: Cast values. Returns: mixed - Merged object or array
Param | Type | Description |
---|---|---|
input | mixed | Mixed input |
Example
`castToArray(null)` returns an empty array `[]`
`castToArray('foo')` returns `['foo']`
`castToArray(['foo'])` returns `['foo']`
`castToArray({ foo: 'bar '})` returns `[{ foo: 'bar' }]`
copyObject(source) ⇒ mixed
Kind: global function Summary: Create a deep copy of an object or an array. Returns: mixed - Copy of the given value
Param | Type | Description |
---|---|---|
source | mixed | Source object/primitive to copy |
escapeSql(arg, quote, force) ⇒ mixed
Kind: global function Summary: Escape SQL argument. Returns: mixed - Escaped string or an object or and array of escaped strings
Param | Type | Default | Description |
---|---|---|---|
arg | mixed | Argument to escape | |
quote | string | "'\"'" | Quote type, either " or ' |
force | boolean | false | Flag to force quotes |
Example
escapeSql takes a value (string, number, boolean, null) and escapes it if
it should be escaped. Second argument can be either the quote type (' and ")
are accepted. Third argument is force flag to force quote. If second argument
is a boolea
4 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
9 months ago
7 months ago
8 months ago
9 months ago
8 months ago
8 months ago
9 months ago
8 months ago
10 months ago
11 months ago
8 months ago
7 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago