FluroUtils

FluroUtils

A static service that provides useful helper functions and tools for other Fluro services

Methods

(static) arrayIDs(array, asObjectID) → {Array}

Source:
Cleans and maps an array of objects to an array of IDs
Example
//Returns ['5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927']
FluroUtils.arrayIDs([{_id:'5cb3d8b3a2219970e6f86927'}, {_id:'5cb3d8b3a2219970e6f86927'}, null, '5cb3d8b3a2219970e6f86927'])
Parameters:
Name Type Description
array Array An array of objects or object ids
asObjectID Boolean Whether or not to map the ids as Mongo ObjectIds
Returns:
An array of Ids
Type
Array

(static) comma(array, path) → {String}

Source:
A helpful class that can take an array of values and return them as a comma seperated string, If the values are objects, then a property to use as the string representation can be specified
Example
//Returns 'cat, dog, bird'
FluroUtils.comma(['cat', 'dog', 'bird']);

//Returns 'cat, dog, bird'
FluroUtils.comma([{title:'cat'}, {title:'dog'}, {title:'bird'}], 'title');
Parameters:
Name Type Description
array Array The array of values to translate
path String An optional property key to use for each value
Returns:
The resulting comma seperated string
Type
String

(static) errorMessage(error) → {String}

Source:
Helper function for retrieving a human readable error message from server error response objects
Parameters:
Name Type Description
error Object The error object to translate
Returns:
The resulting human readable error message
Type
String

(static) getDefaultValueForField() → {String|Number|Object}

Source:
A helper function to extract a default value from a fluro field definition
Returns:
The default value
Type
String | Number | Object

(static) getStringID(input, asObjectID) → {String}

Source:
Returns a specified _id for an object
Example
//Returns '5cb3d8b3a2219970e6f86927'
FluroUtils.getStringID('5cb3d8b3a2219970e6f86927')

//Returns true
typeof FluroUtils.getStringID({_id:'5cb3d8b3a2219970e6f86927', title, ...}) == 'string';
//Returns true
typeof FluroUtils.getStringID({_id:'5cb3d8b3a2219970e6f86927'}, true) == 'object';
Parameters:
Name Type Description
input Object An object that is or has an _id property
asObjectID Boolean Whether to convert to a Mongo ObjectId
Returns:
Will return either a string or a Mongo ObjectId
Type
String

(static) guid() → {String}

Source:
A helpful function that can create a globally unique id
Example
//Returns 20354d7a-e4fe-47af-8ff6-187bca92f3f9
FluroUtils.guid()
Returns:
The new guid
Type
String

(static) hash(array, key) → {Object}

Source:
A helpful function for creating a fast hash object that can be used for more efficient loops
Example
//Returns {something:[{title:'test', definition:'something'}]}
FluroUtils.mapReduce([{title:'test', definition:'something'}], 'definition');
Parameters:
Name Type Description
array Array The array to reduce
key String The key or path to the property to group by
Returns:
A hash object literal
Type
Object

(static) mapParameters(parameters) → {String}

Source:
A helpful function that can take a keyed object literal and map it to url query string parameters
Example
//Returns &this=that&hello=world
FluroUtils.mapParameters({"this":"that", "hello":"world"})
Parameters:
Name Type Description
parameters Object The object you want to transalte
Returns:
The query string
Type
String

(static) matchInArray(array, path, value, operator) → {Array}

Source:
A helpful function that can return a subset of an array compared to specified criteria, This is usually used to evaluate expressions on Fluro forms
Example
//Returns {name:'Jerry', age:26} as that is only item in the array that matches the criteria
FluroUtils.matchInArray([{name:'Jerry', age:26}, {name:'Susan', age:19}], 'age', 26, '>=');
Parameters:
Name Type Description
array Array The array you want to filter
path String The path to the property you want to compare on each item in the array
value String The value to compare with
operator String Can be Possible options are ('>', '<', '>=', '<=', 'in', '==') Defaults to '==' (Is equal to)
Returns:
An array that contains all items that matched
Type
Array