jsonstore-js
Version:
A javascript JSON data store with manifold abilities of data processing
34 lines (27 loc) • 688 B
JavaScript
;
var referenceTypes = {
'array': true,
'object': true
};
var commonKeyTypes = {
'string': true,
'number': true
};
var type = function type(data) {
return Object.prototype.toString.call(data).slice(8, -1).toLowerCase();
};
var isReferenceType = function isReferenceType(data) {
return referenceTypes[type(data)] || false;
};
var isCommonKeyType = function isCommonKeyType(key) {
return commonKeyTypes[type(key)] || false;
};
var copy = function copy(data) {
return isReferenceType(data) ? JSON.parse(JSON.stringify(data)) : data;
};
module.exports = {
type: type,
copy: copy,
isReferenceType: isReferenceType,
isCommonKeyType: isCommonKeyType
};