fdboost
Version:
Performance enhanced utilities for FoundationDB
50 lines (49 loc) • 1.42 kB
text/coffeescript
###*
* Type codes dictionary.
* null
* {integer} date
* {integer} array
* {integer} object
* {Function} get Returns typeCode value for name.
###
module.exports =
'undefined': 0
'string': 1
'integer': 2
'double': 3
'boolean': 4
'null': 5
'datetime': 6
'array': 7
'object': 8
'function': 9
###*
* Gets type code value for name.
*
* {string} value Value to test type for.
* {integer} Type code value
###
'get': (value) ->
switch typeof value
when 'undefined' then
when 'string' then
when 'number'
if (value % 1 is 0) then
else
when 'boolean' then
when 'function' then
else
if (value is null) then
else if (value instanceof Date) then
else if (value instanceof Array) then
else if (Buffer.isBuffer(value))
throw new TypeError("Value cannot be a buffer")
else if (value instanceof Object) then
else
throw new TypeError('Value must either be a string, integer, double, boolean, date, array, object or function')
* {integer} undefined
* {integer} string
* {integer} integer
* {integer} double
* {integer} boolean
* {integer}