UNPKG

tastypie

Version:

Tastypie is a webservice API framework for Node.js based on Django's Tastypie Framework. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces

31 lines (27 loc) 961 B
var kindOf = require('./kindOf'); var GLOBAL = require('./GLOBAL'); /** * Convert array-like object into array */ function toArray(val){ var ret = [], kind = kindOf(val), n; if (val != null) { if ( val.length == null || kind === 'String' || kind === 'Function' || kind === 'RegExp' || val === GLOBAL ) { //string, regexp, function have .length but user probably just want //to wrap value into an array.. ret[ret.length] = val; } else { //window returns true on isObject in IE7 and may have length //property. `typeof NodeList` returns `function` on Safari so //we can't use it (#58) n = val.length; while (n--) { ret[n] = val[n]; } } } return ret; } module.exports = toArray;