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.3 to 0.0.4

10

build/utils.js

@@ -106,4 +106,4 @@ 'use strict';

copyOne = {};
for (var _key in data) {
copyOne[_key] = this.deepCopy(data[_key]);
for (var key in data) {
copyOne[key] = this.deepCopy(data[key]);
}

@@ -200,3 +200,3 @@ } else if (this.isArray(data)) {

}
if (keyName) n[keyName] = key;
if (keyName) n[keyName] = i;
list.push(n);

@@ -207,4 +207,4 @@ }

toObject: function toObject(list) {
var idName = arguments.length <= 1 || arguments[1] === undefined ? 'id' : arguments[1];
var hasNum = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var idName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
var hasNum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

@@ -211,0 +211,0 @@ var listO = {};

@@ -1,2 +0,2 @@

"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};(function(global,factory){(typeof exports==="undefined"?"undefined":_typeof(exports))==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.heyUtils=factory()})((typeof window==="undefined"?"undefined":_typeof(window))=="object"?window:(typeof global==="undefined"?"undefined":_typeof(global))=="object"?global:undefined,function(){"use strict";var heyUtils={isObject:function isObject(input){return Object.prototype.toString.call(input)==="[object Object]"},isArray:function isArray(input){return input instanceof Array||Object.prototype.toString.call(input)==="[object Array]"},isDate:function isDate(input){return input instanceof Date||Object.prototype.toString.call(input)==="[object Date]"},isNumber:function isNumber(input){return input instanceof Number||Object.prototype.toString.call(input)==="[object Number]"},isString:function isString(input){return input instanceof String||Object.prototype.toString.call(input)==="[object String]"},isBoolean:function isBoolean(input){return typeof input=="boolean"},isFunction:function isFunction(input){return typeof input=="function"},isNull:function isNull(input){return input===undefined||input===null},isPlainObject:function isPlainObject(obj){if(obj&&Object.prototype.toString.call(obj)==="[object Object]"&&obj.constructor===Object&&!hasOwnProperty.call(obj,"constructor")){var key;for(key in obj){}return key===undefined||hasOwnProperty.call(obj,key)}return false},extend:function extend(){var options,name,src,copy,copyIsArray,clone,target=arguments[0]||{},i=1,length=arguments.length,deep=false;if(typeof target==="boolean"){deep=target;target=arguments[1]||{};i=2}if((typeof target==="undefined"?"undefined":_typeof(target))!=="object"&&!this.isFunction(target)){target={}}if(length===i){target=this;--i}for(;i<length;i++){if((options=arguments[i])!=null){for(name in options){src=target[name];copy=options[name];if(target===copy){continue}if(deep&&copy&&(this.isPlainObject(copy)||(copyIsArray=this.isArray(copy)))){if(copyIsArray){copyIsArray=false;clone=src&&this.isArray(src)?src:[]}else {clone=src&&this.isPlainObject(src)?src:{}}target[name]=this.extend(deep,clone,copy)}else if(copy!==undefined){target[name]=copy}}}}return target},freeze:function freeze(obj){var _this=this;var that=this;Object.freeze(obj);Object.keys(obj).forEach(function(key,value){if(that.isObject(obj[key])){_this.deepFreeze(obj[key])}});return obj},copy:function copy(data){var copyOne=null;if(this.isObject(data)){copyOne={};for(var _key in data){copyOne[_key]=this.deepCopy(data[_key])}}else if(this.isArray(data)){copyOne=[];var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=data[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var index=_step.value;copyOne.push(this.deepCopy(index))}}catch(err){_didIteratorError=true;_iteratorError=err}finally {try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally {if(_didIteratorError){throw _iteratorError}}}}else {copyOne=data}return copyOne},valueForKeypath:function valueForKeypath(obj,keypath){var array=null;if(this.isArray(keypath)){array=keypath}else if(this.isString(keypath)){array=keypath.split(".")}if(array===null){return null}if(array.length>1){var first=array.shift();if(!obj[first]||_typeof(obj[first])!=="object"){return null}return this.valueForKeypath(obj[first],array)}return obj[array[0]]},setValueForKeypath:function setValueForKeypath(obj,keypath,value){var array=null;if(this.isArray(keypath)){array=keypath}else if(this.isString(keypath)){array=keypath.split(".")}if(array===null){return false}if(array.length>1){var first=array.shift();if(!obj[first]||_typeof(obj[first])!=="object"){obj[first]={}}this.setValueForKeypath(obj[first],array,value);return false}obj[array[0]]=value;return true},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(keyName)n[keyName]=key;list.push(n)}return listO},toObject:function toObject(list){var idName=arguments.length<=1||arguments[1]===undefined?"id":arguments[1];var hasNum=arguments.length<=2||arguments[2]===undefined?false:arguments[2];var listO={};for(var i=0;i<list.length;i++){var n=list[i];if(idName=="count"){listO[i]=n}else {listO[n[idName]]=n;if(hasNum){listO[n[idName]].count=i}}}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}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}}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}}return null},removeLocal:function removeLocal(name){if(window.localStorage&&JSON&&name){window.localStorage[name]=null}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");
"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};(function(global,factory){(typeof exports==="undefined"?"undefined":_typeof(exports))==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.heyUtils=factory()})((typeof window==="undefined"?"undefined":_typeof(window))=="object"?window:(typeof global==="undefined"?"undefined":_typeof(global))=="object"?global:undefined,function(){"use strict";var heyUtils={isObject:function isObject(input){return Object.prototype.toString.call(input)==="[object Object]"},isArray:function isArray(input){return input instanceof Array||Object.prototype.toString.call(input)==="[object Array]"},isDate:function isDate(input){return input instanceof Date||Object.prototype.toString.call(input)==="[object Date]"},isNumber:function isNumber(input){return input instanceof Number||Object.prototype.toString.call(input)==="[object Number]"},isString:function isString(input){return input instanceof String||Object.prototype.toString.call(input)==="[object String]"},isBoolean:function isBoolean(input){return typeof input=="boolean"},isFunction:function isFunction(input){return typeof input=="function"},isNull:function isNull(input){return input===undefined||input===null},isPlainObject:function isPlainObject(obj){if(obj&&Object.prototype.toString.call(obj)==="[object Object]"&&obj.constructor===Object&&!hasOwnProperty.call(obj,"constructor")){var key;for(key in obj){}return key===undefined||hasOwnProperty.call(obj,key)}return false},extend:function extend(){var options,name,src,copy,copyIsArray,clone,target=arguments[0]||{},i=1,length=arguments.length,deep=false;if(typeof target==="boolean"){deep=target;target=arguments[1]||{};i=2}if((typeof target==="undefined"?"undefined":_typeof(target))!=="object"&&!this.isFunction(target)){target={}}if(length===i){target=this;--i}for(;i<length;i++){if((options=arguments[i])!=null){for(name in options){src=target[name];copy=options[name];if(target===copy){continue}if(deep&&copy&&(this.isPlainObject(copy)||(copyIsArray=this.isArray(copy)))){if(copyIsArray){copyIsArray=false;clone=src&&this.isArray(src)?src:[]}else {clone=src&&this.isPlainObject(src)?src:{}}target[name]=this.extend(deep,clone,copy)}else if(copy!==undefined){target[name]=copy}}}}return target},freeze:function freeze(obj){var _this=this;var that=this;Object.freeze(obj);Object.keys(obj).forEach(function(key,value){if(that.isObject(obj[key])){_this.deepFreeze(obj[key])}});return obj},copy:function copy(data){var copyOne=null;if(this.isObject(data)){copyOne={};for(var key in data){copyOne[key]=this.deepCopy(data[key])}}else if(this.isArray(data)){copyOne=[];var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=data[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var index=_step.value;copyOne.push(this.deepCopy(index))}}catch(err){_didIteratorError=true;_iteratorError=err}finally {try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally {if(_didIteratorError){throw _iteratorError}}}}else {copyOne=data}return copyOne},valueForKeypath:function valueForKeypath(obj,keypath){var array=null;if(this.isArray(keypath)){array=keypath}else if(this.isString(keypath)){array=keypath.split(".")}if(array===null){return null}if(array.length>1){var first=array.shift();if(!obj[first]||_typeof(obj[first])!=="object"){return null}return this.valueForKeypath(obj[first],array)}return obj[array[0]]},setValueForKeypath:function setValueForKeypath(obj,keypath,value){var array=null;if(this.isArray(keypath)){array=keypath}else if(this.isString(keypath)){array=keypath.split(".")}if(array===null){return false}if(array.length>1){var first=array.shift();if(!obj[first]||_typeof(obj[first])!=="object"){obj[first]={}}this.setValueForKeypath(obj[first],array,value);return false}obj[array[0]]=value;return true},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(keyName)n[keyName]=i;list.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(idName=="count"){listO[i]=n}else {listO[n[idName]]=n;if(hasNum){listO[n[idName]].count=i}}}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}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}}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}}return null},removeLocal:function removeLocal(name){if(window.localStorage&&JSON&&name){window.localStorage[name]=null}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},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}};return heyUtils});
{
"name": "hey-utils",
"version": "0.0.3",
"description": "js-utils, js, util",
"main": "build/utils.js",
"repository": {
"type": "git",
"url": "git+https://github.com/hey-ui/hey-utils.git"
},
"keywords": [
"utils",
"hey"
],
"author": {
"name": "alias"
},
"license": "The MIT License",
"_npmUser": {
"name": "vvpvvp",
"email": "alias8516@sina.com.cn"
},
"dependencies": {},
"bugs": {
"url": "https://github.com/hey-ui/hey-utils/issues"
},
"babel": {
"presets": ["es2015"]
},
"scripts": {
"build": "babel ./utils.js -d build",
"min": "babel build/utils.js --minified --no-babelrc -o build/utils.min.js",
"test": "mocha --compilers js:babel-core/register ./test/*.js"
},
"homepage": "https://github.com/hey-ui/hey-utils#readme",
"readmeFilename": "README.md"
"name": "hey-utils",
"version": "0.0.4",
"description": "js-utils, js, util",
"main": "build/utils.js",
"repository": {
"type": "git",
"url": "git+https://github.com/hey-ui/hey-utils.git"
},
"keywords": [
"utils",
"hey"
],
"author": {
"name": "alias"
},
"license": "The MIT License",
"_npmUser": {
"name": "vvpvvp",
"email": "alias8516@sina.com.cn"
},
"dependencies": {},
"bugs": {
"url": "https://github.com/hey-ui/hey-utils/issues"
},
"babel": {
"presets": ["es2015"]
},
"scripts": {
"build": "babel ./utils.js -d build",
"min": "babel build/utils.js --minified --no-babelrc -o build/utils.min.js",
"test": "mocha --compilers js:babel-core/register ./test/*.js"
},
"homepage": "https://github.com/hey-ui/hey-utils#readme",
"readmeFilename": "README.md"
}
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.heyUtils = factory();
}((typeof window == 'object' ? window : typeof global == 'object' ? global : this), function () {
"use strict";
const heyUtils = {
isObject: function (input) {
return Object.prototype.toString.call(input) === '[object Object]';
},
isArray: function (input) {
return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
},
isDate: function (input) {
return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
},
isNumber: function (input) {
return input instanceof Number || Object.prototype.toString.call(input) === '[object Number]';
},
isString: function (input) {
return input instanceof String || Object.prototype.toString.call(input) === '[object String]';
},
isBoolean: function (input) {
return typeof input == 'boolean';
},
isFunction: function (input) {
return typeof input == 'function';
},
isNull: function (input) {
return input === undefined || input === null;
},
isPlainObject: function (obj) {
if (obj && Object.prototype.toString.call(obj) === "[object Object]" && obj.constructor === Object && !hasOwnProperty.call(obj, "constructor")) {
var key;
for (key in obj) {}
return key === undefined || hasOwnProperty.call(obj, key);
}
return false;
},
extend: function () {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
i = 2;
}
if (typeof target !== "object" && !this.isFunction(target)) {
target = {};
}
if (length === i) {
target = this;
--i;
}
for (; i < length; i++) {
if ((options = arguments[i]) != null) {
for (name in options) {
src = target[name];
copy = options[name];
if (target === copy) {
continue;
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.heyUtils = factory();
}((typeof window == 'object' ? window : typeof global == 'object' ? global : this), function () {
"use strict";
const heyUtils = {
isObject: function (input) {
return Object.prototype.toString.call(input) === '[object Object]';
},
isArray: function (input) {
return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
},
isDate: function (input) {
return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
},
isNumber: function (input) {
return input instanceof Number || Object.prototype.toString.call(input) === '[object Number]';
},
isString: function (input) {
return input instanceof String || Object.prototype.toString.call(input) === '[object String]';
},
isBoolean: function (input) {
return typeof input == 'boolean';
},
isFunction: function (input) {
return typeof input == 'function';
},
isNull: function (input) {
return input === undefined || input === null;
},
isPlainObject: function (obj) {
if (obj && Object.prototype.toString.call(obj) === "[object Object]" && obj.constructor === Object && !hasOwnProperty.call(obj, "constructor")) {
var key;
for (key in obj) {}
return key === undefined || hasOwnProperty.call(obj, key);
}
if (deep && copy && (this.isPlainObject(copy) || (copyIsArray = this.isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;
clone = src && this.isArray(src) ? src : [];
} else {
clone = src && this.isPlainObject(src) ? src : {};
return false;
},
extend: function () {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
i = 2;
}
if (typeof target !== "object" && !this.isFunction(target)) {
target = {};
}
if (length === i) {
target = this;
--i;
}
for (; i < length; i++) {
if ((options = arguments[i]) != null) {
for (name in options) {
src = target[name];
copy = options[name];
if (target === copy) {
continue;
}
if (deep && copy && (this.isPlainObject(copy) || (copyIsArray = this.isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;
clone = src && this.isArray(src) ? src : [];
} else {
clone = src && this.isPlainObject(src) ? src : {};
}
target[name] = this.extend(deep, clone, copy);
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
target[name] = this.extend(deep, clone, copy);
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
return target;
},
freeze(obj) {
const that = this;
Object.freeze(obj);
Object.keys(obj).forEach((key, value) => {
if (that.isObject(obj[key])) {
this.deepFreeze(obj[key]);
}
});
return obj;
},
copy(data) {
let copyOne = null;
if (this.isObject(data)) {
copyOne = {};
for (const key in data) {
copyOne[key] = this.deepCopy(data[key]);
}
} else if (this.isArray(data)) {
copyOne = [];
for (const index of data) {
copyOne.push(this.deepCopy(index));
}
} else {
copyOne = data;
}
return copyOne;
},
valueForKeypath(obj, keypath) {
let array = null;
if (this.isArray(keypath)) {
array = keypath;
} else if (this.isString(keypath)) {
array = keypath.split('.');
}
if (array === null) {
return null;
}
if (array.length > 1) {
const first = array.shift();
return target;
},
freeze(obj) {
const that = this;
Object.freeze(obj);
Object.keys(obj).forEach((key, value) => {
if (that.isObject(obj[key])) {
this.deepFreeze(obj[key]);
}
});
return obj;
},
copy(data) {
let copyOne = null;
if (this.isObject(data)) {
copyOne = {};
for (const key in data) {
copyOne[key] = this.deepCopy(data[key]);
}
} else if (this.isArray(data)) {
copyOne = [];
for (const index of data) {
copyOne.push(this.deepCopy(index));
}
} else {
copyOne = data;
}
return copyOne;
},
valueForKeypath(obj, keypath) {
let array = null;
if (this.isArray(keypath)) {
array = keypath;
} else if (this.isString(keypath)) {
array = keypath.split('.');
}
if (array === null) {
return null;
}
if (array.length > 1) {
const first = array.shift();
if (!obj[first] || typeof obj[first] !== 'object') {
return null;
}
return this.valueForKeypath(obj[first], array)
}
return obj[array[0]];
},
setValueForKeypath(obj, keypath, value) {
let array = null;
if (this.isArray(keypath)) {
array = keypath;
} else if (this.isString(keypath)) {
array = keypath.split('.');
}
if (array === null) {
return false;
}
if (array.length > 1) {
const first = array.shift();
if (!obj[first] || typeof obj[first] !== 'object') {
return null;
}
return this.valueForKeypath(obj[first], array)
}
return obj[array[0]];
},
setValueForKeypath(obj, keypath, value) {
let array = null;
if (this.isArray(keypath)) {
array = keypath;
} else if (this.isString(keypath)) {
array = keypath.split('.');
}
if (array === null) {
return false;
}
if (array.length > 1) {
const first = array.shift();
if (!obj[first] || typeof obj[first] !== 'object') {
obj[first] = {};
}
this.setValueForKeypath(obj[first], array, value);
return false;
}
obj[array[0]] = value;
return true;
},
toArray(object, keyName, arg3) {
let titleName = '';
if (!this.isObject(object)) {
return [];
}
if (this.isString(arg3)) {
titleName = arg3;
}
let listO = [];
for (let i in object) {
let value = object[i];
let n = {};
if (this.isObject(value)) {
n = value;
} else {
n[titleName] = value;
}
if (keyName) n[keyName] = key;
list.push(n);
}
return listO;
},
toObject(list, idName = 'id', hasNum = false) {
const listO = {};
for (var i = 0; i < list.length; i++) {
const n = list[i];
if (idName == 'count') {
listO[i] = n;
} else {
listO[n[idName]] = n;
if (hasNum) {
listO[n[idName]].count = i;
}
}
}
return listO;
},
saveLocal(name, value) {
if (window.localStorage && JSON && name && value) {
if (typeof value == 'object') {
value = JSON.stringify(value);
}
window.localStorage[name] = value;
return true;
}
return false;
},
getLocal(name, type) {
if (window.localStorage && JSON && name) {
const 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;
}
}
return null;
},
getLocal2Json(name) {
if (window.localStorage && JSON && name) {
const data = window.localStorage[name];
if (!this.isNull(data)) {
try {
return JSON.parse(data);
} catch (e) {
console.error(`取数转换json错误${e}`);
return '';
}
} else {
return data;
}
}
return null;
},
removeLocal(name) {
if (window.localStorage && JSON && name) {
window.localStorage[name] = null;
}
return null;
},
saveCookie(name, value, minSec, path) {
const cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (name && cookieEnabled) {
path = path || '/';
if (typeof value == 'object') {
value = JSON.stringify(value);
}
let exp;
if (minSec) {
exp = new Date(); // new Date("December 31, 9998");
exp.setTime(exp.getTime() + minSec * 1000);
}
if (!obj[first] || typeof obj[first] !== 'object') {
obj[first] = {};
}
this.setValueForKeypath(obj[first], array, value);
return false;
}
obj[array[0]] = value;
return true;
},
toArray(object, keyName, arg3) {
let titleName = '';
if (!this.isObject(object)) {
return [];
}
if (this.isString(arg3)) {
titleName = arg3;
}
let listO = [];
for (let i in object) {
let value = object[i];
let n = {};
if (this.isObject(value)) {
n = value;
} else {
n[titleName] = value;
}
if (keyName) n[keyName] = i;
list.push(n);
}
return listO;
},
toObject(list, idName = 'id', hasNum = false) {
const listO = {};
for (var i = 0; i < list.length; i++) {
const n = list[i];
if (idName == 'count') {
listO[i] = n;
} else {
listO[n[idName]] = n;
if (hasNum) {
listO[n[idName]].count = i;
}
}
}
return listO;
},
saveLocal(name, value) {
if (window.localStorage && JSON && name && value) {
if (typeof value == 'object') {
value = JSON.stringify(value);
}
window.localStorage[name] = value;
return true;
}
return false;
},
getLocal(name, type) {
if (window.localStorage && JSON && name) {
const 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;
}
}
return null;
},
getLocal2Json(name) {
if (window.localStorage && JSON && name) {
const data = window.localStorage[name];
if (!this.isNull(data)) {
try {
return JSON.parse(data);
} catch (e) {
console.error(`取数转换json错误${e}`);
return '';
}
} else {
return data;
}
}
return null;
},
removeLocal(name) {
if (window.localStorage && JSON && name) {
window.localStorage[name] = null;
}
return null;
},
saveCookie(name, value, minSec, path) {
const cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (name && cookieEnabled) {
path = path || '/';
if (typeof value == 'object') {
value = JSON.stringify(value);
}
let exp;
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}`;
document.cookie = `${name}=${escape(value)}${minSec?(`;expires=${exp.toGMTString()}`) : ''};path=${path}`;
return true;

@@ -251,0 +251,0 @@ }

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