Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hey-utils

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hey-utils - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

326

build/utils.js

@@ -5,4 +5,2 @@ 'use strict';

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
(function (global, factory) {

@@ -13,5 +11,3 @@ (typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.heyUtils = factory();

var _heyUtils;
var heyUtils = (_heyUtils = {
var heyUtils = {
isObject: function isObject(input) {

@@ -174,177 +170,189 @@ return Object.prototype.toString.call(input) === '[object Object]';

if (array.length > 0) {
return this.valueForKeypath(value, array);
return this.getKeyValue(value, array);
}
return value;
}
}, _defineProperty(_heyUtils, 'getKeyValue', function getKeyValue(obj, keypath, value, orignal) {
if (!this.isObject(obj)) {
return false;
}
var array = null;
if (this.isArray(keypath)) {
array = keypath;
} else if (this.isString(keypath)) {
array = keypath.split('.');
orignal = obj;
}
if (array == null || array.length == 0) {
return false;
}
var children = null;
var index = 0;
var key = array.shift();
var keyTest = key.match(new RegExp("^(\\w+)\\[(\\d+)\\]$"));
if (keyTest) {
key = keyTest[1];
index = keyTest[2];
children = obj[key];
if (this.isArray(children) && children.length > index) {
},
setKeyValue: function setKeyValue(obj, keypath, value, orignal) {
if (!this.isObject(obj)) {
return false;
}
var array = null;
if (this.isArray(keypath)) {
array = keypath;
} else if (this.isString(keypath)) {
array = keypath.split('.');
orignal = obj;
}
if (array == null || array.length == 0) {
return false;
}
var children = null;
var index = 0;
var key = array.shift();
var keyTest = key.match(new RegExp("^(\\w+)\\[(\\d+)\\]$"));
if (keyTest) {
key = keyTest[1];
index = keyTest[2];
children = obj[key];
if (this.isArray(children) && children.length > index) {
if (array.length > 0) {
return this.setKeyValue(children[index], array, value, orignal);
}
children[index] = value;
}
} else {
if (array.length > 0) {
return this.setValueForKeypath(children[index], array, value, orignal);
return this.setKeyValue(obj[key], array, value, orignal);
}
children[index] = value;
obj[key] = value;
}
} else {
if (array.length > 0) {
return this.setValueForKeypath(obj[key], array, value, orignal);
return orignal;
},
toArray: function toArray(object, keyName, arg3) {
var titleName = '';
if (!this.isObject(object)) {
return [];
}
obj[key] = value;
}
return orignal;
}), _defineProperty(_heyUtils, 'toArray', function toArray(object, keyName, arg3) {
var titleName = '';
if (!this.isObject(object)) {
return [];
}
if (this.isString(arg3)) {
titleName = arg3;
}
var listO = [];
for (var i in object) {
var value = object[i];
var n = {};
if (this.isObject(value)) {
n = value;
} else {
n[titleName] = value;
if (this.isString(arg3)) {
titleName = arg3;
}
if (keyName) n[keyName] = i;
listO.push(n);
}
return listO;
}), _defineProperty(_heyUtils, 'toObject', function toObject(list) {
var idName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
var hasNum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var listO = [];
for (var i in object) {
var value = object[i];
var n = {};
if (this.isObject(value)) {
n = value;
} else {
n[titleName] = value;
}
if (keyName) n[keyName] = i;
listO.push(n);
}
return listO;
},
toObject: function toObject(list) {
var idName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
var hasNum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var listO = {};
for (var i = 0; i < list.length; i++) {
var n = list[i];
if (this.isObject(n)) {
if (idName == 'count') {
listO[i] = n;
var listO = {};
for (var i = 0; i < list.length; i++) {
var n = list[i];
if (this.isObject(n)) {
if (idName == 'count') {
listO[i] = n;
} else {
listO[n[idName]] = n;
if (hasNum) {
listO[n[idName]].count = i;
}
}
} else {
listO[n[idName]] = n;
if (hasNum) {
listO[n[idName]].count = i;
}
listO[n] = n;
}
} else {
listO[n] = n;
}
}
return listO;
}), _defineProperty(_heyUtils, 'saveLocal', function saveLocal(name, value) {
if (window.localStorage && JSON && name && value) {
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object') {
value = JSON.stringify(value);
return listO;
},
saveLocal: function saveLocal(name, value) {
if (window.localStorage && JSON && name && value) {
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object') {
value = JSON.stringify(value);
}
window.localStorage[name] = value;
return true;
}
window.localStorage[name] = value;
return true;
}
return false;
}), _defineProperty(_heyUtils, 'getLocal', function getLocal(name, type) {
if (window.localStorage && JSON && name) {
var data = window.localStorage[name];
if (type && type == 'json' && data !== undefined) {
try {
return JSON.parse(data);
} catch (e) {
console.error('取数转换json错误' + e);
return '';
return false;
},
getLocal: function getLocal(name, type) {
if (window.localStorage && JSON && name) {
var data = window.localStorage[name];
if (type && type == 'json' && data !== undefined) {
try {
return JSON.parse(data);
} catch (e) {
console.error('取数转换json错误' + e);
return '';
}
} else {
return data;
}
} else {
return data;
}
}
return null;
}), _defineProperty(_heyUtils, 'getLocal2Json', function getLocal2Json(name) {
if (window.localStorage && JSON && name) {
var data = window.localStorage[name];
if (!this.isNull(data)) {
try {
return JSON.parse(data);
} catch (e) {
console.error('取数转换json错误' + e);
return '';
return null;
},
getLocal2Json: function getLocal2Json(name) {
if (window.localStorage && JSON && name) {
var data = window.localStorage[name];
if (!this.isNull(data)) {
try {
return JSON.parse(data);
} catch (e) {
console.error('取数转换json错误' + e);
return '';
}
} else {
return data;
}
} else {
return data;
}
}
return null;
}), _defineProperty(_heyUtils, 'removeLocal', function removeLocal(name) {
if (window.localStorage && JSON && name) {
window.localStorage[name] = null;
}
return null;
}), _defineProperty(_heyUtils, 'saveCookie', function saveCookie(name, value, minSec, path) {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (name && cookieEnabled) {
path = path || '/';
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object') {
value = JSON.stringify(value);
return null;
},
removeLocal: function removeLocal(name) {
if (window.localStorage && JSON && name) {
window.localStorage[name] = null;
}
var exp = undefined;
if (minSec) {
exp = new Date(); // new Date("December 31, 9998");
exp.setTime(exp.getTime() + minSec * 1000);
}
return null;
},
saveCookie: function saveCookie(name, value, minSec, path) {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (name && cookieEnabled) {
path = path || '/';
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object') {
value = JSON.stringify(value);
}
var exp = undefined;
if (minSec) {
exp = new Date(); // new Date("December 31, 9998");
exp.setTime(exp.getTime() + minSec * 1000);
}
document.cookie = name + '=' + escape(value) + (minSec ? ';expires=' + exp.toGMTString() : '') + ';path=' + path;
return true;
}
return false;
}), _defineProperty(_heyUtils, 'getCookie', function getCookie(name) {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (name && cookieEnabled) {
var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
if (arr !== null) {
return unescape(arr[2]);
document.cookie = name + '=' + escape(value) + (minSec ? ';expires=' + exp.toGMTString() : '') + ';path=' + path;
return true;
}
}
return null;
}), _defineProperty(_heyUtils, 'clearCookie', function clearCookie() {
var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
if (keys) {
for (var i = keys.length; i--;) {
document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString();
return false;
},
getCookie: function getCookie(name) {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (name && cookieEnabled) {
var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
if (arr !== null) {
return unescape(arr[2]);
}
}
return null;
},
clearCookie: function clearCookie() {
var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
if (keys) {
for (var i = keys.length; i--;) {
document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString();
}
}
},
removeCookie: function removeCookie(name, path) {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (name && cookieEnabled) {
var exp = new Date();
path = path || '/';
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
if (cval !== null) document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString() + ';path=' + path;
return true;
}
return false;
},
uuid: function uuid() {
var s4 = function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
};
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}
}), _defineProperty(_heyUtils, 'removeCookie', function removeCookie(name, path) {
var cookieEnabled = navigator.cookieEnabled ? true : false;
if (name && cookieEnabled) {
var exp = new Date();
path = path || '/';
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(name);
if (cval !== null) document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString() + ';path=' + path;
return true;
}
return false;
}), _defineProperty(_heyUtils, 'uuid', function uuid() {
var s4 = function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
};
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
}), _heyUtils);
};
heyUtils.valueForKeypath = heyUtils.getKeyValue;

@@ -351,0 +359,0 @@ heyUtils.setValueForKeypath = heyUtils.setKeyValue;

{
"name": "hey-utils",
"version": "0.0.13",
"version": "0.0.14",
"description": "js-utils, js, util",

@@ -5,0 +5,0 @@ "main": "build/utils.js",

@@ -137,7 +137,7 @@ (function (global, factory) {

if (array.length > 0) {
return this.valueForKeypath(value, array)
return this.getKeyValue(value, array)
}
return value;
},
getKeyValue(obj, keypath, value, orignal) {
setKeyValue(obj, keypath, value, orignal) {
if (!this.isObject(obj)) {

@@ -166,3 +166,3 @@ return false;

if (array.length > 0) {
return this.setValueForKeypath(children[index], array, value, orignal);
return this.setKeyValue(children[index], array, value, orignal);
}

@@ -173,3 +173,3 @@ children[index] = value;

if (array.length > 0) {
return this.setValueForKeypath(obj[key], array, value, orignal);
return this.setKeyValue(obj[key], array, value, orignal);
}

@@ -176,0 +176,0 @@ obj[key] = value;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc