atma-utils
Advanced tools
Comparing version 0.1.39 to 0.1.41
@@ -161,2 +161,3 @@ var _Array_slice, | ||
obj_defaults, | ||
obj_clean, | ||
obj_extendDescriptors, | ||
@@ -336,2 +337,81 @@ obj_extendDescriptorsDefaults; | ||
} | ||
/** | ||
* Remove all NULL properties, optionally also all falsy-ies | ||
*/ | ||
obj_clean = function (json, opts) { | ||
var _a; | ||
if (opts === void 0) { opts = { | ||
removePrivate: false, | ||
skipProperties: null, | ||
removeEmptyArrays: false, | ||
removeFalsy: false | ||
}; } | ||
if (json == null || typeof json !== 'object') { | ||
return json; | ||
} | ||
if (is_ArrayLike(json)) { | ||
var arr = json; | ||
var i = 0; | ||
var notNullIndex = -1; | ||
for (; i < arr.length; i++) { | ||
var val = arr[i]; | ||
if (val != null) { | ||
notNullIndex = i; | ||
} | ||
obj_clean(val, opts); | ||
} | ||
// clean all last nullable values | ||
if (notNullIndex + 1 < arr.length) { | ||
arr.splice(notNullIndex + 1); | ||
} | ||
return json; | ||
} | ||
if (is_Object(json)) { | ||
for (var key in json) { | ||
if (opts.skipProperties != null && key in opts.skipProperties) { | ||
delete json[key]; | ||
continue; | ||
} | ||
if (opts.ignoreProperties != null && key in opts.ignoreProperties) { | ||
continue; | ||
} | ||
if (opts.removePrivate === true && key[0] === '_') { | ||
delete json[key]; | ||
continue; | ||
} | ||
var val = json[key]; | ||
if ((_a = opts.shouldRemove) === null || _a === void 0 ? void 0 : _a.call(opts, key, val)) { | ||
delete json[key]; | ||
continue; | ||
} | ||
if (isDefault(val, opts)) { | ||
if (opts.strictProperties != null && key in opts.strictProperties && val != null) { | ||
continue; | ||
} | ||
delete json[key]; | ||
continue; | ||
} | ||
if (opts.deep !== false) { | ||
obj_clean(val, opts); | ||
} | ||
if (opts.removeEmptyArrays && is_ArrayLike(val) && val.length === 0) { | ||
delete json[key]; | ||
} | ||
} | ||
return json; | ||
} | ||
return json; | ||
} | ||
function isDefault(x, opts) { | ||
if (x == null) { | ||
return true; | ||
} | ||
if (opts.removeFalsy && (x === '' || x === false)) { | ||
return true; | ||
} | ||
if (opts.removeEmptyArrays && is_ArrayLike(x) && x.length === 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
obj_extendDescriptors; | ||
@@ -832,6 +912,6 @@ obj_extendDescriptorsDefaults; | ||
}, | ||
"catch": function (cb) { | ||
catch: function (cb) { | ||
return this.fail(cb); | ||
}, | ||
"finally": function (cb) { | ||
finally: function (cb) { | ||
return this.always(cb); | ||
@@ -838,0 +918,0 @@ } |
189
lib/utils.js
@@ -29,2 +29,54 @@ (function(factory){ | ||
_Object_defineProperty; | ||
var is_Function, | ||
is_Object, | ||
is_Array, | ||
is_ArrayLike, | ||
is_String, | ||
is_notEmptyString, | ||
is_rawObject, | ||
is_Date, | ||
is_DOM, | ||
is_NODE; | ||
(function(){ | ||
is_Function = function (x) { | ||
return typeof x === 'function'; | ||
} | ||
is_Object = function (x) { | ||
return x != null && typeof x === 'object'; | ||
} | ||
is_Array = function (arr) { | ||
return (arr != null && | ||
typeof arr === 'object' && | ||
typeof arr.length === 'number' && | ||
typeof arr.slice === 'function'); | ||
} | ||
is_ArrayLike = is_Array; | ||
is_String = function (x) { | ||
return typeof x === 'string'; | ||
} | ||
is_notEmptyString = function (x) { | ||
return typeof x === 'string' && x !== ''; | ||
} | ||
is_rawObject = function (x) { | ||
return x != null && typeof x === 'object' && x.constructor === Object; | ||
} | ||
is_Date = function (x) { | ||
if (x == null || typeof x !== 'object') { | ||
return false; | ||
} | ||
if (x.getFullYear != null && isNaN(x) === false) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function is_PromiseLike(x) { | ||
return x != null && typeof x === 'object' && typeof x.then === 'function'; | ||
} | ||
function is_Observable(x) { | ||
return x != null && typeof x === 'object' && typeof x.subscribe === 'function'; | ||
} | ||
is_DOM = typeof window !== 'undefined' && window.navigator != null; | ||
is_NODE = !is_DOM; | ||
}()); | ||
var obj_copyProperty, | ||
@@ -42,2 +94,3 @@ obj_getProperty, | ||
obj_defaults, | ||
obj_clean, | ||
obj_extendDescriptors; | ||
@@ -231,2 +284,81 @@ (function(){ | ||
} | ||
/** | ||
* Remove all NULL properties, optionally also all falsy-ies | ||
*/ | ||
obj_clean = function (json, opts) { | ||
var _a; | ||
if (opts === void 0) { opts = { | ||
removePrivate: false, | ||
skipProperties: null, | ||
removeEmptyArrays: false, | ||
removeFalsy: false | ||
}; } | ||
if (json == null || typeof json !== 'object') { | ||
return json; | ||
} | ||
if (is_ArrayLike(json)) { | ||
var arr = json; | ||
var i = 0; | ||
var notNullIndex = -1; | ||
for (; i < arr.length; i++) { | ||
var val = arr[i]; | ||
if (val != null) { | ||
notNullIndex = i; | ||
} | ||
obj_clean(val, opts); | ||
} | ||
// clean all last nullable values | ||
if (notNullIndex + 1 < arr.length) { | ||
arr.splice(notNullIndex + 1); | ||
} | ||
return json; | ||
} | ||
if (is_Object(json)) { | ||
for (var key in json) { | ||
if (opts.skipProperties != null && key in opts.skipProperties) { | ||
delete json[key]; | ||
continue; | ||
} | ||
if (opts.ignoreProperties != null && key in opts.ignoreProperties) { | ||
continue; | ||
} | ||
if (opts.removePrivate === true && key[0] === '_') { | ||
delete json[key]; | ||
continue; | ||
} | ||
var val = json[key]; | ||
if ((_a = opts.shouldRemove) === null || _a === void 0 ? void 0 : _a.call(opts, key, val)) { | ||
delete json[key]; | ||
continue; | ||
} | ||
if (isDefault(val, opts)) { | ||
if (opts.strictProperties != null && key in opts.strictProperties && val != null) { | ||
continue; | ||
} | ||
delete json[key]; | ||
continue; | ||
} | ||
if (opts.deep !== false) { | ||
obj_clean(val, opts); | ||
} | ||
if (opts.removeEmptyArrays && is_ArrayLike(val) && val.length === 0) { | ||
delete json[key]; | ||
} | ||
} | ||
return json; | ||
} | ||
return json; | ||
} | ||
function isDefault(x, opts) { | ||
if (x == null) { | ||
return true; | ||
} | ||
if (opts.removeFalsy && (x === '' || x === false)) { | ||
return true; | ||
} | ||
if (opts.removeEmptyArrays && is_ArrayLike(x) && x.length === 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
obj_extendDescriptors; | ||
@@ -401,54 +533,2 @@ var obj_extendDescriptorsDefaults; | ||
}()); | ||
var is_Function, | ||
is_Object, | ||
is_Array, | ||
is_ArrayLike, | ||
is_String, | ||
is_notEmptyString, | ||
is_rawObject, | ||
is_Date, | ||
is_DOM, | ||
is_NODE; | ||
(function(){ | ||
is_Function = function (x) { | ||
return typeof x === 'function'; | ||
} | ||
is_Object = function (x) { | ||
return x != null && typeof x === 'object'; | ||
} | ||
is_Array = function (arr) { | ||
return (arr != null && | ||
typeof arr === 'object' && | ||
typeof arr.length === 'number' && | ||
typeof arr.slice === 'function'); | ||
} | ||
is_ArrayLike = is_Array; | ||
is_String = function (x) { | ||
return typeof x === 'string'; | ||
} | ||
is_notEmptyString = function (x) { | ||
return typeof x === 'string' && x !== ''; | ||
} | ||
is_rawObject = function (x) { | ||
return x != null && typeof x === 'object' && x.constructor === Object; | ||
} | ||
is_Date = function (x) { | ||
if (x == null || typeof x !== 'object') { | ||
return false; | ||
} | ||
if (x.getFullYear != null && isNaN(x) === false) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
function is_PromiseLike(x) { | ||
return x != null && typeof x === 'object' && typeof x.then === 'function'; | ||
} | ||
function is_Observable(x) { | ||
return x != null && typeof x === 'object' && typeof x.subscribe === 'function'; | ||
} | ||
is_DOM = typeof window !== 'undefined' && window.navigator != null; | ||
is_NODE = !is_DOM; | ||
}()); | ||
var str_format, | ||
@@ -776,6 +856,6 @@ str_dedent; | ||
}, | ||
"catch": function (cb) { | ||
catch: function (cb) { | ||
return this.fail(cb); | ||
}, | ||
"finally": function (cb) { | ||
finally: function (cb) { | ||
return this.always(cb); | ||
@@ -1421,2 +1501,3 @@ } | ||
obj_defineProperty: obj_defineProperty, | ||
obj_clean: obj_clean, | ||
is_Function: is_Function, | ||
@@ -1423,0 +1504,0 @@ is_Array: is_Array, |
{ | ||
"name": "atma-utils", | ||
"description": "Helpers", | ||
"version": "0.1.39", | ||
"version": "0.1.41", | ||
"author": "Alexander Kit <alex.kit@atmajs.com>", | ||
@@ -22,3 +22,3 @@ "repository": { | ||
"atma-loader-babel": ">0.0.0", | ||
"atma-loader-ts": "^1.1.11" | ||
"atma-loader-ts": "^1.1.12" | ||
}, | ||
@@ -100,4 +100,3 @@ "scripts": { | ||
} | ||
}, | ||
"dependencies": {} | ||
} | ||
} |
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
183618
5868