Members
(static) injectModule
- Source:
Helper function for including external javascript resources
This ensures that scripts are only included a single time on each page
Methods
(static) arrayIDs(array, asObjectID) → {Array}
- Source:
Cleans and maps an array of objects to an array of IDs
Example
//Returns ['5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927', '5cb3d8b3a2219970e6f86927']
fluro.utils.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'
fluro.utils.comma(['cat', 'dog', 'bird']);
//Returns 'cat, dog, bird'
fluro.utils.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) currencySymbol(currency) → {String}
- Source:
A function that will take a currency string and return the symbol
Example
//Returns £
fluro.utils.currencySymbol('gbp');
//Returns $
fluro.utils.currencySymbol('usd');
Parameters:
Name | Type | Description |
---|---|---|
currency |
String | The currency |
Returns:
The symbol
- 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) extractFromArray(array, path, options) → {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 [26, 19] as all the values
fluro.utils.extractFromArray([{name:'Jerry', age:26}, {name:'Susan', age:19}], 'age');
//Returns 45
fluro.utils.extractFromArray([{name:'Jerry', age:26}, {name:'Susan', age:19}], 'age', {sum:true});
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 |
options |
Object | Pass through extra options for how to extract the values |
Returns:
An array of all values retrieved from the array, unless options specifies otherwise
- Type
- Array
(static) formatCurrency(value, currency) → {String}
- Source:
A function that will take an integer and a currency string and return a formatted numeric amount rounded to 2 decimal places
Example
//Returns £10.00
fluro.utils.formatCurrency(1000, 'gbp');
//Returns $10.00
fluro.utils.formatCurrency(1000, 'usd');
Parameters:
Name | Type | Description |
---|---|---|
value |
Integer | The amount in cents |
currency |
String | The currency to format |
Returns:
The formatted value
- 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) getFlattenedFields(fields, trail, trail) → {Array}
- Source:
Helper function for getting a flattened list of all nested fields
defined for a definition in Fluro
Parameters:
Name | Type | Description |
---|---|---|
fields |
Array | The array of fields |
trail |
Array | An array to append trails to (required) |
trail |
Array | An array to append titles to (required) |
Returns:
A flattened list of all fields with their nested trails and titles
- Type
- Array
(static) getStringID(input, asObjectID) → {String}
- Source:
Returns a specified _id for an object
Example
//Returns '5cb3d8b3a2219970e6f86927'
fluro.utils.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
fluro.utils.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'}]}
fluro.utils.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) injectScript(url) → {Promise}
- Source:
Helper function for including external javascript resources
This ensures that scripts are only included a single time on each page
Parameters:
Name | Type | Description |
---|---|---|
url |
String | The URL of the script to import |
Returns:
A promise that resolves once the script has been included on the page
- Type
- Promise
(static) machineName(string) → {String}
- Source:
Helper function for cleaning strings to use as database ids
Parameters:
Name | Type | Description |
---|---|---|
string |
String | The string to clean eg. (Awesome Event!) |
Returns:
A cleaned and formatted string eg. (awesomeEvent)
- Type
- String
(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
fluro.utils.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
fluro.utils.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
(static) processCardPrioritySort(card) → {Integer}
- Source:
Helper function for sorting process cards by priority
Parameters:
Name | Type | Description |
---|---|---|
card |
Object | The process card to sort |
Returns:
An integer representing it's sorting priority
- Type
- Integer