Module ringo/utils
Functions
- format(format)
- getJavaStack(error)
- getScriptStack(error)
- jsonDateReviver(key, value)
- readOnlyPropertyDesc(obj, name, desc)
- readWritePropertyDesc(obj, name, desc)
- timer(fn)
- writeOnlyPropertyDesc(obj, name, desc)
format (format)
A simple string formatter. If the first argument is a format string containing a number of curly bracket pairs {} as placeholders, the same number of following arguments will be used to replace the curly bracket pairs in the format string. If the first argument is not a string or does not contain any curly brackets, the arguments are simply concatenated to a string and returned.
Parameters
| String | format | string, followed by a variable number of values |
Returns
| String | the formatted string |
getJavaStack (error)
Get a rendered JavaScript stack trace from a caught error.
Parameters
| Error | error | an error object |
Returns
| String | the rendered JavaScript stack trace |
getScriptStack (error)
Get a rendered JavaScript stack trace from a caught error.
Parameters
| Error | error | an error object |
Returns
| String | the rendered JavaScript stack trace |
jsonDateReviver (key, value)
JSON reviver function for Date values. Pass this as second argument to JSON.parse to convert stringified dates back into Date objects. Borrowed from http://www.west-wind.com/weblog/posts/729630.aspx
Parameters
| key | the JSON key | |
| value | the JSON value |
readOnlyPropertyDesc (obj, name, desc)
Create a read-only property descriptor to be used as third argument in Object.defineProperty that maps a property to a property in another object.
The third argument is optional and can be used to define additional settings on the descriptor such as enumerable, writable, or configurable.
Parameters
| obj | the target object | |
| name | the target property name | |
| desc | optional: the descriptor object, or undefined |
Returns
| a property descriptor object that maps to a property in a target object |
readWritePropertyDesc (obj, name, desc)
Create a read-write property descriptor to be used as third argument in Object.defineProperty that maps a property to a property in another object.
The third argument is optional and can be used to define additional settings on the descriptor such as enumerable, writable, or configurable.
Parameters
| obj | the target object | |
| name | the target property name | |
| desc | optional: the descriptor object, or undefined |
Returns
| a property descriptor object that maps to a property in a target object |
writeOnlyPropertyDesc (obj, name, desc)
Create a write-only property descriptor to be used as third argument in Object.defineProperty that maps a property to a property in another object.
The third argument is optional and can be used to define additional settings on the descriptor such as enumerable, writable, or configurable.
Parameters
| obj | the target object | |
| name | the target property name | |
| desc | optional: the descriptor object, or undefined |
Returns
| a property descriptor object that maps to a property in a target object |
