A library of utility functions
npm install @webantic/util* util/array
* ~move(array, fromIndex, toIndex) ⇒ Array.<any>
* ~addToSet(array, item) ⇒ Array.<any>
* ~addToSetInPlace(set, item) ⇒ boolean
* ~first(array) ⇒ any
* ~last(array) ⇒ any
* ~eachUntil(array, callback)
* ~remove(array, item) ⇒ Array.<any>
* ~removeAll(array, item) ⇒ Array.<any>
* ~forceArray(input) ⇒ Array.<any>
* ~mapAsync(array, callback, onComplete)
* ~forEachAsync(array, cb, onComplete)
util/array | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | an array containing the element to move |
| fromIndex | number | the location of the element to move |
| toIndex | number | the destination index |
util/array item, addingArray.<any> - the new array | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | an array to potentially add item to |
| item | any | an item to ensure is within array |
util/array item to set if it isset was modified boolean - true if set was modified | Param | Type | Description |
| --- | --- | --- |
| set | Array.<any> | a set to potentially add item to |
| item | any | an item to ensure is within set |
util/array any - the first element of the array | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | the array to search in |
util/array any - the last element of the array | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | the array to search in |
util/array callback for each item in an array,false | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | of items to iterate |
| callback | ForEachCallback | the function to invoke for each element in the supplied array |
util/array Array.<any> - The new array | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | The array to remove item from |
| item | any | The item to remove. Cannot be an object |
Example
``js`
var array = ['a', 'b', 'c']
remove(array, 'b') // returns ['a', 'c']
util/array from array
Returns: Array.<any> - The new array
Export: | Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | The array to remove all occurrences of
item from |
| item | any | The item to remove |Example
`js
var array = ['a', 'b', 'b', 'c']
removeAll(array, 'b') // returns ['a', 'c']
`
$3
Kind: inner method of util/array
Summary: wraps the input in an array if it isn't already one
Returns: Array.<any> - always an array | Param | Type |
| --- | --- |
| input | any |
$3
Map an array's values, iterating asynchronouslyKind: inner method of util/array
| Param | Description |
| --- | --- |
| array | The array to map |
| callback | A callback to receive the current element & index. Should return the new value |
| onComplete | A callback which will be called when all elements have been processed |
$3
Iterate the elements in an array, calling the user-supplied callback on each element asynchronouslyKind: inner method of util/array
| Param | Type | Description |
| --- | --- | --- |
| array | Array.<any> | The array to iterate |
| cb | ArrayTypes.MapCallbackFunction | the callback to receive the element(s) |
| onComplete | ArrayTypes.CallbackFunction | A callback to be called when all elements have been iterated |
util/blaze
* util/blaze
* ~attachAPI(blaze, API)
* ~onCountChanged(callback)
$3
Attach a DDP connection to Blaze so that it is available in templates' this.subscribeKind: inner method of util/blaze
| Param | Type | Description |
| --- | --- | --- |
| blaze | Object | a reference to Blaze |
| API | Object | The DDP connection to attachs |
$3
Add a function to get called when the count changesKind: inner method of util/blaze
| Param | Type |
| --- | --- |
| callback | function |
util/collection
* util/collection
* ~insert(collection, items) ⇒ ICollectionReturn
* ~update(collection, items) ⇒ ICollectionReturn
* ~remove(collection, _ids) ⇒ ICollectionReturn
* [~caseInsensitiveSelector(fieldName, str, [wordIsPrefix])](#module_util/collection..caseInsensitiveSelector) ⇒ Object
* ~selectorFromParams(selectorParams) ⇒ Object
* ~getObserverHandlers(context, collection) ⇒ IObserveHandlers
* ~mapHelpersToThis(pureHelpers) ⇒ any
* ~IFailedOps : Object
* ~ICollectionReturn : Object
* ~IObserveHandlers : Object
* ~ISelectorParams : Object
$3
Kind: inner method of util/collection
Summary: Inserts a number of items into the given collection
Export: | Param | Type | Description |
| --- | --- | --- |
| collection | Mongo.Collection | A Mongo.Collection |
| items | Array.<object> | the items to insert. |
$3
Kind: inner method of util/collection
Summary: Updates a number of items into the given collection
Export: | Param | Type | Description |
| --- | --- | --- |
| collection | Mongo.Collection | A Mongo.Collection |
| items | Array.<object> | the items to update. The _id field is used as a selector, the rest of the object as the modifier |
$3
Kind: inner method of util/collection
Summary: Remvoves a number of items by their _id from the
given collection
Export: | Param | Type | Description |
| --- | --- | --- |
| collection | Mongo.Collection | A Mongo.Collection |
| _ids | Array.<string> | the _ids of the items to remove. |
$3
Kind: inner method of util/collection
Summary: Generates a selector for a field which will perform a case-insensitive
lookup for the given value
Returns: Object - the Mongo selector object
Export: | Param | Type | Default | Description |
| --- | --- | --- | --- |
| fieldName | string | | the name of the field to query |
| str | string | | the value to query |
| [wordIsPrefix] | boolean | false | whether the supplied value for str is a prefix or the whole query |
$3
Kind: inner method of util/collection
Summary: Parses "skip", "limit", "sort", "before" and "since" into a selector and options object
Returns: Object - The constructed selector & options objects
Export: | Param | Type | Description |
| --- | --- | --- |
| selectorParams | ISelectorParams | An object containing any/all of the defined keys. "createdOrUpdated" can be either "createdAt" (default) or "updatedAt". It determines what "before" and "since" act upon |
$3
Kind: inner method of util/collection
Summary: Returns a map of default observe callback handlers
Returns: IObserveHandlers - The map of callback handlers
Export: | Param | Type | Description |
| --- | --- | --- |
| context | any | The
this context. It should contain added, changed and removed methods |
| collection | string | The name of the collection to add/change/remove documents to/from |$3
Takes an object of helpers and wraps them in functions that use
the this context and pass it as the first arg. Allows thisless functions
to be used as collection helpersKind: inner method of util/collection
| Param | Type | Description |
| --- | --- | --- |
| pureHelpers | any | helpers to map |
$3
Kind: inner typedef of util/collection
Properties| Name | Type | Description |
| --- | --- | --- |
| code | number | the error code |
| message | string | the error message |
| additional | any | meta information about the error |
$3
Kind: inner typedef of util/collection
Properties| Name | Type | Description |
| --- | --- | --- |
| success | boolean | Whether no operations failed |
| failed | Array.<IFailedOps> | an array of objects detailling failed operations |
| succeeded | Array.<(any\|boolean)> | an array of objects detailling documents of successful operations |
$3
Kind: inner typedef of util/collection
Properties| Name | Type |
| --- | --- |
| added | function |
| changed | function |
| removed | function |
$3
Kind: inner typedef of util/collection
Properties| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [skip] | number | | A number indicating how many matching documents to skip |
| [limit] | number | | A number indicating the maximum number of documents to return |
| [sort] | Object.<number> | | An object whose keys equate to database column names and whose values are either 1 or -1 to indicate sort order |
| [createdOrUpdated] | string | "\"createdAt\"" | |
| [before] | Date \| string \| number | | A parsable representation of a date. Only documents whose createdAt or updatedAt (as defined by createdOrUpdated) are greater than the supplied value will be returned |
| [since] | Date \| string \| number | | A parsable representation of a date. Only documents whose createdAt or updatedAt (as defined by createdOrUpdated) are less than the supplied value will be returned |
| [fields] | Object.<number> | | An object whose keys equate to database column names and whose values are either 1 or 0 to indicate inclusion or exclusion |
util/config
* util/config
* ~Configuration
* [new Configuration(collection, Meteor, [Tracker], [connection])](#new_module_util/config..Configuration_new)
* ~StandaloneConfiguration
* new StandaloneConfiguration()
$3
Kind: inner class of util/config
#### new Configuration(collection, Meteor, [Tracker], [connection])
A configuration class - provides a DB-backed, environment variable / meteor.settings populated set of config values
| Param | Type | Description |
| --- | --- | --- |
| collection | Mongo.Collection | the config collection |
| Meteor | Object | a reference to the Meteor object |
| [Tracker] | Object | an optional reference to Tracker - will be mocked in a non-reactive way if not supplied |
| [connection] | Object | an optional override for the DDP connection to use to subscribe to the config pub |
$3
Kind: inner class of util/config
#### new StandaloneConfiguration()
A configuration class - provides an environment variable / codebase-populated set of config values
util/data
* util/data
* [~titles([flatten])](#module_util/data..titles) ⇒ Array.<object> \| Array.<string>
* [~genders([flatten])](#module_util/data..genders) ⇒ Array.<object> \| Array.<string>
* [~maritalStatuses([flatten])](#module_util/data..maritalStatuses) ⇒ Array.<object> \| Array.<string>
* [~nationalities([flatten])](#module_util/data..nationalities) ⇒ Array.<object> \| Array.<string>
$3
Kind: inner method of util/data
Summary: provides a list of name titles
Returns: Array.<object> \| Array.<string> - If flatten is true, an array of string values otherwise an array of objects with name
and camelized value
Export: | Param | Type | Default | Description |
| --- | --- | --- | --- |
| [flatten] | boolean | false | whether to return an array of plain text values |
$3
Kind: inner method of util/data
Summary: provides a list of genders
Returns: Array.<object> \| Array.<string> - If flatten is true, an array of string values otherwise an array of objects with name
and camelized value
Export: | Param | Type | Default | Description |
| --- | --- | --- | --- |
| [flatten] | boolean | false | whether to return an array of plain text values |
$3
Kind: inner method of util/data
Summary: provides a list of maritalStatuses
Returns: Array.<object> \| Array.<string> - If flatten is true, an array of string values otherwise an array of objects with name
and camelized value
Export: | Param | Type | Default | Description |
| --- | --- | --- | --- |
| [flatten] | boolean | false | whether to return an array of plain text values |
$3
Kind: inner method of util/data
Summary: provides a list of nationalities
Returns: Array.<object> \| Array.<string> - If flatten is true, an array of string values otherwise an array of objects with name
and camelized value
Export: | Param | Type | Default | Description |
| --- | --- | --- | --- |
| [flatten] | boolean | false | whether to return an array of plain text values |
util/date
* util/date
* ~randomBetween(from, to) ⇒ Date
* [~getDate([startEnd], [prevNext], [interval])](#module_util/date..getDate) ⇒ Date
* [~yesterday([startEnd])](#module_util/date..yesterday) ⇒ Date
* [~tomorrow([startEnd])](#module_util/date..tomorrow) ⇒ Date
* [~lastWeek([startEnd])](#module_util/date..lastWeek) ⇒ Date
* [~nextWeek([startEnd])](#module_util/date..nextWeek) ⇒ Date
* [~lastMonth([startEnd])](#module_util/date..lastMonth) ⇒ Date
* [~nextMonth([startEnd])](#module_util/date..nextMonth) ⇒ Date
* ~getPreviousDay(day) ⇒ string
* ~getNextDay(day) ⇒ string
$3
Kind: inner method of util/date
Summary: gets a random date between two others
Returns: Date - the random date
Export: | Param | Type | Description |
| --- | --- | --- |
| from | Date | random date must be greater than this |
| to | Date | random date must be less than this |
$3
Gets a Date object of a given offset from nowKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [startEnd] | string | | Either 'start' or 'end' to round the date to the start or end of the day |
| [prevNext] | string | "'prev'" | |
| [interval] | string | "'day'" | |
$3
Return a Date object from 24 hours agoKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Description |
| --- | --- | --- |
| [startEnd] | string | either 'start' or 'end' - determines whether to round the date to the start or end of the day |
$3
Return a Date object for 24 hours in the futureKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Description |
| --- | --- | --- |
| [startEnd] | string | either 'start' or 'end' - determines whether to round the date to the start or end of the day |
$3
Return a Date object from 7 days agoKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Description |
| --- | --- | --- |
| [startEnd] | string | either 'start' or 'end' - determines whether to round the date to the start or end of the day |
$3
Return a Date object for 7 days in the futureKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Description |
| --- | --- | --- |
| [startEnd] | string | either 'start' or 'end' - determines whether to round the date to the start or end of the day |
$3
Return a Date object from 30 days agoKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Description |
| --- | --- | --- |
| [startEnd] | string | either 'start' or 'end' - determines whether to round the date to the start or end of the day |
$3
Return a Date object for 30 days in the futureKind: inner method of util/date
Returns: Date - the date object
| Param | Type | Description |
| --- | --- | --- |
| [startEnd] | string | either 'start' or 'end' - determines whether to round the date to the start or end of the day |
$3
Can be passed either a full or three-letter day name and will return the previous day's nameKind: inner method of util/date
Returns: string - the name of the previous day
| Param | Type | Description |
| --- | --- | --- |
| day | string | a full or three-letter day name |
$3
Can be passed either a full or three-letter day name and will return the next day's nameKind: inner method of util/date
Returns: string - the name of the next day
| Param | Type | Description |
| --- | --- | --- |
| day | string | a full or three-letter day name |
util/emitter
* util/emitter
* .MultiEmitter
* new MultiEmitter()
* .Emitter
* new Emitter()
* .MultiEmitter#listen(event, callback)
* .MultiEmitter#broadcast(event, value)
* .MultiEmitter#removeListeners(event)
* .Emitter#listen()
* .Emitter#broadcast(value)
* .Emitter#removeListeners()
$3
Kind: static class of util/emitter
Export:
#### new MultiEmitter()
Slightly more advanced event emitter style class that allows listening to different events via string arguments
$3
Kind: static class of util/emitter
Export:
#### new Emitter()
Basic class that represents an event that can be listened to and broadcasted
$3
Add a callback to be ran whenver this event is broadcastedKind: static method of util/emitter
| Param | Description |
| --- | --- |
| event | the event as a string to be listened to |
| callback | the callback to run whenever said event is triggered |
$3
Broadcast an event of the given typeKind: static method of util/emitter
| Param | Description |
| --- | --- |
| event | even type to broadcast |
| value | value to be passed to each callback |
$3
Remove all attached listeners for a specific event typeKind: static method of util/emitter
| Param |
| --- |
| event |
$3
Add a callback to be ran whenver this event is broadcastedKind: static method of util/emitter
$3
Calls all callbacks that have been registered with the given valueKind: static method of util/emitter
| Param | Description |
| --- | --- |
| value | value to broadcast, if any |
$3
Remove all attached listenersKind: static method of util/emitter
util/http
* util/http
* [~getBaseParameter([{ location, type, required }])](#module_util/http..getBaseParameter) ⇒ Object
* ~requiredBodyString(extendedDef) ⇒ Object
* ~requiredBodyNumber(extendedDef) ⇒ Object
* ~requiredBodyDate(extendedDef) ⇒ Object
* ~requiredBodyBoolean(extendedDef) ⇒ Object
* ~requiredBodyObject(extendedDef) ⇒ Object
* ~optionalBodyString(extendedDef) ⇒ Object
* ~optionalBodyNumber(extendedDef) ⇒ Object
* ~optionalBodyDate(extendedDef) ⇒ Object
* ~optionalBodyBoolean(extendedDef) ⇒ Object
* ~optionalBodyObject(extendedDef) ⇒ Object
$3
Kind: inner method of util/http
Summary: returns a basic Swagger parameter field
Export: | Param | Type | Default |
| --- | --- | --- |
| [{ location, type, required }] | \* | {} |
$3
Kind: inner method of util/http
Summary: scaffolds a required body string parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a required body number parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a required body string parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a required body boolean parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a required body object parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a optional body string parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a optional body number parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a optional body string parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a optional body boolean parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
$3
Kind: inner method of util/http
Summary: scaffolds a optional body object parameter
Export: | Param | Type | Description |
| --- | --- | --- |
| extendedDef | Object | the rest of the definition |
util/image
* util/image
* ~dataURIToBlob(dataURI) ⇒ blob
* ~toDataURI(file, callback)
$3
Kind: inner method of util/image
Summary: converts a data uri to a blob://
Returns: blob - the uri as a blob
Export: | Param | Type | Description |
| --- | --- | --- |
| dataURI | string | the data uri to convert into a blob |
$3
Kind: inner method of util/image
Summary: converts an image file to a data uri
Export: | Param | Type | Description |
| --- | --- | --- |
| file | File | the image file to convert |
| callback | function | a function to receive the result of the conversion |
util/location
$3
Kind: inner method of util/location
Summary: Get the distance in KM between two latitude/longitude pairs
Returns: number - The distance between the two points, in KM
Export: | Param | Type | Description |
| --- | --- | --- |
| lat1 | number | The first latitude |
| lon1 | number | The first longitude |
| lat2 | number | The second latitude |
| lon2 | number | The second longitude |
util/meteor
* util/meteor
* [~assert(assertion, errorCode, [meta])](#module_util/meteor..assert)
* ~assertString(value, name)
* ~assertBoolean(value, name)
* ~assertNumber(value, name)
* ~assertInt(value, name)
* ~assertObject(value, name)
* ~assertArray(value, name, type)
* ~assertDate(value, options)
$3
Kind: inner method of util/meteor
Summary: if the assertion is falsey, throws
an error
Export: | Param | Type | Description |
| --- | --- | --- |
| assertion | any | anything that should be truthy to not throw an error |
| errorCode | number | the error code |
| [meta] | any | additional info to include with the error |
$3
Assert that the typeof ${value} is 'string'Kind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| name | the name of the value being checked |
$3
Assert that the typeof ${value} is 'boolean'Kind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| name | the name of the value being checked |
$3
Assert that the typeof ${value} is 'number'Kind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| name | the name of the value being checked |
$3
Assert that the ${value} is an integerKind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| name | the name of the value being checked |
$3
Assert that the typeof ${value} is 'object'Kind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| name | the name of the value being checked |
$3
Assert that the ${value} is an arrayKind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| name | the name of the value being checked |
| type | the expected datatype of every item within the supposed array |
$3
Assert that the typeof ${value} is 'Date'Kind: inner method of util/meteor
| Param | Description |
| --- | --- |
| value | any value to check the type of |
| options | whether to parse the date |
util/model
* util/model
* ~ModelDefinition
* new ModelDefinition(t)
* .ModelDefinition#auto(func) ⇒ this
* .ModelDefinition#maybe() ⇒ this
* [.ModelDefinition#max(val, [exclusive])](#module_util/model..ModelDefinition.ModelDefinition+max) ⇒ this
* [.ModelDefinition#min(val, [exclusive])](#module_util/model..ModelDefinition.ModelDefinition+min) ⇒ this
* .ModelDefinition#maxCount(val) ⇒ this
* .ModelDefinition#minCount(val) ⇒ this
* .ModelDefinition#subtype(format) ⇒ this
* .ModelDefinition#prop(name, value) ⇒ this
* .ModelDefinition#props(properties) ⇒ this
* .ModelDefinition#elems(definition) ⇒ this
* .ModelDefinition#regex(pattern) ⇒ this
* .ModelDefinition#in(values) ⇒ this
* [.ModelDefinition#join(model, [field], where)](#module_util/model..ModelDefinition.ModelDefinition+join) ⇒ this
* .ModelDefinition#other(key, value) ⇒ this
* ~def ⇒ this
* ~ILinkWhere : Object
* ~ILink : Object
$3
Kind: inner class of util/model
Export: * ~ModelDefinition
* new ModelDefinition(t)
* .ModelDefinition#auto(func) ⇒ this
* .ModelDefinition#maybe() ⇒ this
* [.ModelDefinition#max(val, [exclusive])](#module_util/model..ModelDefinition.ModelDefinition+max) ⇒ this
* [.ModelDefinition#min(val, [exclusive])](#module_util/model..ModelDefinition.ModelDefinition+min) ⇒ this
* .ModelDefinition#maxCount(val) ⇒ this
* .ModelDefinition#minCount(val) ⇒ this
* .ModelDefinition#subtype(format) ⇒ this
* .ModelDefinition#prop(name, value) ⇒ this
* .ModelDefinition#props(properties) ⇒ this
* .ModelDefinition#elems(definition) ⇒ this
* .ModelDefinition#regex(pattern) ⇒ this
* .ModelDefinition#in(values) ⇒ this
* [.ModelDefinition#join(model, [field], where)](#module_util/model..ModelDefinition.ModelDefinition+join) ⇒ this
* .ModelDefinition#other(key, value) ⇒ this
#### new ModelDefinition(t)
Class to generate model definitions
| Param | Type | Description |
| --- | --- | --- |
| t | string | The type for this definition |
#### ModelDefinition.ModelDefinition#auto(func) ⇒ this
Define an autoValue
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| func | function | The autovalue function |
#### ModelDefinition.ModelDefinition#maybe() ⇒ this
Set this field as optional
Kind: static method of ModelDefinition
#### ModelDefinition.ModelDefinition#max(val, [exclusive]) ⇒ this
Set this field's maximum allowed value / length
Kind: static method of ModelDefinition
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| val | number | | The max value / length |
| [exclusive] | boolean | false | Whether this value is an exclusive max |
#### ModelDefinition.ModelDefinition#min(val, [exclusive]) ⇒ this
Set this field's minimum allowed value / length
Kind: static method of ModelDefinition
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| val | number | | The min value / length |
| [exclusive] | boolean | false | Whether this value is an exclusive min |
#### ModelDefinition.ModelDefinition#maxCount(val) ⇒ this
Set the maximum number of allowed elements in an array field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| val | number | The max number of elements |
#### ModelDefinition.ModelDefinition#minCount(val) ⇒ this
Set the minimum number of allowed elements in an array field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| val | number | The min number of elements |
#### ModelDefinition.ModelDefinition#subtype(format) ⇒ this
Set the subtype / format of this field. E.g. "float" for a number type
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| format | string | The format / subtype |
#### ModelDefinition.ModelDefinition#prop(name, value) ⇒ this
Define a single property of an object-type field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| name | string | The property name |
| value | ModelDefinition | The property value |
#### ModelDefinition.ModelDefinition#props(properties) ⇒ this
Define all properties of an object-type field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| properties | \* | The property definitions |
#### ModelDefinition.ModelDefinition#elems(definition) ⇒ this
Define the elements of an array-type field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| definition | ModelDefinition | The definition which applies to all elements |
#### ModelDefinition.ModelDefinition#regex(pattern) ⇒ this
Define a RegEx pattern which applies to a string-type field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| pattern | RegEx | The pattern |
#### ModelDefinition.ModelDefinition#in(values) ⇒ this
Define a list of permitted values for this field
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| values | Array \| ILink | The array of allowed values |
#### ModelDefinition.ModelDefinition#join(model, [field], where) ⇒ this
Define a link to another Model
Kind: static method of ModelDefinition
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| model | string | | The name of the model |
| [field] | string | "'_id'" | The field on the other model to join on |
| where | \* | | An optional selector for items in the foreign model |
#### ModelDefinition.ModelDefinition#other(key, value) ⇒ this
Set a custom definition key
Kind: static method of ModelDefinition
| Param | Type | Description |
| --- | --- | --- |
| key | string | The key name |
| value | \* | The value |
$3
Shorthand to get an instance of ModelDefinitionKind: inner constant of util/model
| Param | Type | Description |
| --- | --- | --- |
| type | string | The type of the field (e.g. 'string' / 'boolean') |
$3
Kind: inner typedef of util/model
Properties| Name | Type |
| --- | --- |
| | \
| util/model | Name | Type |
| --- | --- |
| model | string |
| [field] | string |
| [where] | ILinkWhere |
* util/number
* ~clamp(val, min, max) ⇒ number
* [~random([min], [max])](#module_util/number..random)
* ~pad(num, width, char) ⇒ string
util/number number - the clamped number | Param | Type | Description |
| --- | --- | --- |
| val | number | the number to clamp |
| min | number | the minimum that the number should be |
| max | number | the maximum that the number should be |
util/number | Param | Type | Description |
| --- | --- | --- |
| [min] | number | The minimum acceptable value |
| [max] | number | The maximum acceptable value |
util/number string - the padded number | Param |
| --- |
| num |
| width |
| char |
* util/object
* ~map(object, callback) ⇒ any
* ~transform(object, callback)
* ~forEach()
* ~filter(object, callback) ⇒ any
* ~resolve() ⇒ any \| undefined
* ~didResolve() ⇒ boolean
* ~resolveIf() ⇒ any \| null
* ~resolveSet() ⇒ boolean
* ~transformPathsToObjects(obj) ⇒
* ~flatten(input, _output, _prefix)
* ~flattenAll(input, _output, _prefix)
* ~resolveSetP(outerObj, outerPath, outerVal) ⇒ boolean
* ~mapAsync
* ~transformAsync
util/object ,
setting the result to a new object under a key of
the same name
Returns: any - a new object with the same key names but mapped values
Export: | Param | Type | Description |
| --- | --- | --- |
| object | any | the object whose values to map |
| callback | function | a function to pass each key=>value pair to |
$3
Kind: inner method of util/object
Summary: Like map, but able to transform the key too. Map the object into a completely
different | Param | Description |
| --- | --- |
| object | the object to transform |
| callback | callback to perform the transformation, return an array like [key, value] |
$3
Kind: inner method of util/object
Summary: Like array.forEach, but for an object, gets keys and values
$3
Kind: inner method of util/object
Summary: passes each key=>value pair of an object
to callback, copying them over if the result is
truthy
Returns: any - a filtered copy of the input object
Export: | Param | Type | Description |
| --- | --- | --- |
| object | any | the object whose keys to filter |
| callback | function | the function to pass each key=>value pair to |
$3
Kind: inner method of util/object
Summary: get a nested property of an object by string e.g. resolve(myObj, 'nested.property')
Returns: any \| undefined - resolved value or undefined if intermediate values are undefined
Export:
$3
Kind: inner method of util/object
Summary: report whether an attempt to resolve a nested property of an object
was successful or not.
Returns: boolean - whether the nested property exists
Export:
$3
Kind: inner method of util/object
Summary: same as resolve but sets the property to val
Returns: any \| null - The resolved value or null
Export:
$3
Kind: inner method of util/object
Summary: same as resolve but sets the property to val
Returns: boolean - whether setting was successful
Export:
$3
Transform an entire object by converting all of its keys into object paths using resolveSetKind: inner method of util/object
Returns: obj for convenience, although transformed in place
| Param | Description |
| --- | --- |
| obj | the object to transform (transformed in place) |
$3
Convert a deep object into one which is flat (has a max depth of 1 level). The output object's keys will
use dot notation to symbolise depth.
If a property contains a dot, this will be converted to "[dot]"Kind: inner method of util/object
| Param | Type | Description |
| --- | --- | --- |
| input | object | An input object. Required |
| _output | object | Private param used in recursion |
| _prefix | string | Private param used in recursion |
Example
`js
var deepObj = {person: {profile: {name: 'Carl', age: 26}, password: 'foobar', '.withDot': true}}
var res = flatten(deepObj)
// res === {
// 'person.profile.name': 'Carl',
// 'person.profile.age': 26,
// 'person.password': 'foobar',
// 'person.[dot]withDot': true
// }
`
$3
Convert a deep object into one which is flat (has a max depth of 1 level). The output object's keys will
use dot notation to symbolise depth. Also processes arraysKind: inner method of util/object
| Param | Type | Description |
| --- | --- | --- |
| input | object | An input object. Required |
| _output | object | Private param used in recursion |
| _prefix | string | Private param used in recursion |
Example
`js
var deepObj = {person: {profile: {name: 'Carl', age: 26}, things: ['foo', 'bar'], '.withdot': true}}
flattenAll(deepObj)
// returns {
// 'person.profile.name': 'Carl',
// 'person.profile.age': 26,
// 'person.things.0': 'foo',
// 'person.things.1': 'bar'
// 'person.[dot]withDot: true
// }
`
$3
Kind: inner method of util/object
Summary: same as resolveSet, but will create paths down into
objects where they don't exist
Returns: boolean - whether the op was successful
Export: | Param | Type | Description |
| --- | --- | --- |
| outerObj | object | the object to create the value in |
| outerPath | string | the path (dot notation) into the object |
| outerVal | any | the new value |
$3
Kind: inner typedef of util/object
Summary: passes each key=>value pair to callback` asynchronously, setting the result to a new object under a key of| Param | Type | Description |
| --- | --- | --- |
| object | any | the object whose values to map |
| callback | function | a function to pass each key=>value pair to |
| onComplete | function | a callback which will receive two arguments, error and res |
util/object | Param | Type | Description |
| --- | --- | --- |
| object | any | the object to transform |
| cb | function | callback to perform the transformation, return an array like [key, value] |
| onComplete | function | a callback which will received two arguments, error and res |
* util/popover
* ~open(source, content, options)
* ~openDropdown(source, dropDownItems, options)
* ~ifLet(toCheck, ifCallback, elseCallback)
* ~viewportPosition(element)
* ~addTriangleToFixedElement(element, positionedWhere, pointingAt, container) ⇒
* ~positionFixed(element, relativeTo)
Kind: inner method of util/popover
| Param | Description |
| --- | --- |
| source | the target element this popover should be attached to |
| content | the content to show in the popover |
| options | |
Kind: inner method of [util/popover](#mod