utils/object.js
Helps to work with JS objects. Like finding existing items, whether an item has been changed, or converting item keys to propercase.
Example:app.utils.object.keyProperCase(object);
app.utils.object.changed(leftObject, rightObject, arrayOfKeysToMatch);
app.utils.object.exists(object, key, value);
A module for ac-bundle-app, published by ac-bundle-module.
Install from:
https://www.npmjs.com/package/ac-apps-minimal-utils-object
https://github.com/animatedcreativity/ac-apps-minimal-utils-object
Available Methods: exists, has, changed, keyProperCase
exists
function(list, key, value, parent) {
// console.log(list, key, value, parent);
if (!app.has(parent)) parent = "";
for (var listKey in list) {
var item = list[listKey];
if (app.has(parent)) {
if (item[parent][key] === value) return item;
} else {
if (item[key] === value) return item;
}
}
}
has
function(value) {
return typeof value !== "undefined" && value !== null && value !== "" && value !== false;
}
changed
function(left, right, match, skip) {
if (!app.has(skip)) skip = [];
for (var i=0; i<=match.length-1; i++) {
var key = match[i];
if (
skip.indexOf(key) < 0
&& left[key] !== right[key]
&& (mod.has(left[key]) || mod.has(right[key]))
) {
// console.log(key, left[key], right[key], match);
return key;
}
}
}
keyProperCase
function(obj) {
for (var key in obj) {
var value = obj[key];
delete obj[key];
key = app.utils.string.toProperCase(key);
obj[key] = value;
}
}
Happy Coding!
MIT License: https://choosealicense.com/licenses/mit/
Copyright 2022 Animated Creativity
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.