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

@bnfe/common-utils

Package Overview
Dependencies
Maintainers
5
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bnfe/common-utils - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

235

dist/common-utils.js

@@ -1,234 +0,1 @@

'use strict';
var createQueryString = function createQueryString(options) {
return Object.keys(options).filter(function (key) {
return options[key] !== undefined && options[key] !== "" && ["pfx", "apiKey", "sign", "key"].indexOf(key) < 0;
}).sort().map(function (key) {
return key + "=" + options[key];
}).join("&");
};
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
/**
* Deep clones an object.
* @param obj The object to deep clone.
* @param options Options for deep cloning.
* @returns The deep cloned object.
*/
var deepClone = function deepClone(obj, options) {
if (obj === null || _typeof(obj) !== "object") {
return obj;
}
var preserveNonEnumerable = (options === null || options === void 0 ? void 0 : options.preserveNonEnumerable) || false;
var copy = Array.isArray(obj) ? [] : {};
if (!preserveNonEnumerable) {
var allPropertyKeys = Object.keys(obj).concat(Object.getOwnPropertySymbols(obj));
for (var _i = 0, allPropertyKeys_1 = allPropertyKeys; _i < allPropertyKeys_1.length; _i++) {
var key = allPropertyKeys_1[_i];
if (Object.prototype.propertyIsEnumerable.call(obj, key)) {
copy[key] = deepClone(obj[key], options);
}
}
} else {
for (var key in obj) {
if (Object.prototype.propertyIsEnumerable.call(obj, key) || preserveNonEnumerable) {
copy[key] = deepClone(obj[key], options);
}
}
}
return copy;
};
var distance = function distance(lat1, lng1, lat2, lng2) {
var radLat1 = lat1 * Math.PI / 180.0;
var radLat2 = lat2 * Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
// TODO 数值单位:米 => Math.round(s * 10000) / 10
return s; //返回数值单位:公里
};
/**
* @method 过滤手机号空格以及+86
* @param {Number} tel 手机号
*/
var filterPhone = function filterPhone(tel) {
var phone = String(tel).replace(/[^\d.]+/g, "").replace(/^\+?86/g, "").substring(0, 11);
return phone;
};
/**
* @param date Date类型 new Date()
* @param fmt 格式化类型 yyyy-MM-dd hh:mm:ss
* @returns 时间字符串 2022-03-29 17:22:30
*/
function formatDate(date, fmt) {
var o = {
"M+": date.getMonth() + 1,
"d+": date.getDate(),
"h+": date.getHours(),
"m+": date.getMinutes(),
"s+": date.getSeconds(),
"q+": Math.floor((date.getMonth() + 3) / 3),
S: date.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1,
// eslint-disable-next-line
// @ts-ignore
RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return fmt;
}
/**
* @param dateStr 字符串格式为 2017-02-10 18:20:30
* 注意:此处月、日、时分秒、必须为2位数字,否则报错
* @returns 时间戳
*/
function getTimestamp(dateStr) {
return Date.parse(new Date(dateStr).toString());
}
/**
* @method 获取当前数据类型
* @param {*} obj
*/
var getType = function getType(obj) {
var str = Object.prototype.toString;
var map = {
"[object Boolean]": "boolean",
"[object Number]": "number",
"[object String]": "string",
"[object Function]": "function",
"[object Array]": "array",
"[object Date]": "date",
"[object RegExp]": "regExp",
"[object Undefined]": "undefined",
"[object Null]": "null",
"[object Object]": "object"
};
if (obj instanceof Element) {
return "element";
}
return map[str.call(obj)];
};
var hidePhone = function hidePhone(val) {
return val.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
};
/**
* 判断是否为数组
* @param input 任意值对象
* @returns boolean
*/
function isArray(input) {
return input instanceof Array || Object.prototype.toString.call(input) === "[object Array]";
}
/**
* 判断是否为空
* @param input 任意值对象
* @returns boolean
*/
function isEmpty(input) {
return typeof input === "undefined" || input === null || input === "";
}
/**
* 判断是否为数字
* @param input 任意值对象
* @returns boolean
*/
function isNumber(input) {
return input instanceof Number || Object.prototype.toString.call(input) === "[object Number]";
}
/**
* 生成数字范围内的随机数
* @param min 最小数字
* @param max 最大数字
* @returns number类型
*/
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var randomSort = function randomSort(arr) {
return arr.sort(function () {
return Math.random() - 0.5;
});
};
// 生成uuid
/**
*
* @param len { number }
* @param radix { number }
* @returns { string }
*/
var uuid = function uuid(len, radix) {
if (len === void 0) {
len = 8;
}
if (radix === void 0) {
radix = 16;
}
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
var value = [];
var i = 0;
radix = radix || chars.length;
if (len) {
// Compact form
for (i = 0; i < len; i++) value[i] = chars[0 | Math.random() * radix];
} else {
// rfc4122, version 4 form
var r = void 0;
// rfc4122 requires these characters
/* eslint-disable-next-line */
value[8] = value[13] = value[18] = value[23] = "-";
value[14] = "4";
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
for (i = 0; i < 36; i++) {
if (!value[i]) {
r = 0 | Math.random() * 16;
value[i] = chars[i === 19 ? r & 0x3 | 0x8 : r];
}
}
}
return value.join("");
};
exports.createQueryString = createQueryString;
exports.deepClone = deepClone;
exports.distance = distance;
exports.filterPhone = filterPhone;
exports.formatDate = formatDate;
exports.getTimestamp = getTimestamp;
exports.getType = getType;
exports.hidePhone = hidePhone;
exports.isArray = isArray;
exports.isEmpty = isEmpty;
exports.isNumber = isNumber;
exports.random = random;
exports.randomSort = randomSort;
exports.uuid = uuid;
"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}exports.createQueryString=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]&&""!==t[e]&&["pfx","apiKey","sign","key"].indexOf(e)<0})).sort().map((function(e){return e+"="+t[e]})).join("&")},exports.deepClone=function e(r,n){if(null===r||"object"!==t(r))return r;var o=(null==n?void 0:n.preserveNonEnumerable)||!1,a=Array.isArray(r)?[]:{};if(o)for(var i in r)(Object.prototype.propertyIsEnumerable.call(r,i)||o)&&(a[i]=e(r[i],n));else for(var c=0,u=Object.keys(r).concat(Object.getOwnPropertySymbols(r));c<u.length;c++){var i=u[c];Object.prototype.propertyIsEnumerable.call(r,i)&&(a[i]=e(r[i],n))}return a},exports.distance=function(t,e,r,n){var o=t*Math.PI/180,a=r*Math.PI/180,i=o-a,c=e*Math.PI/180-n*Math.PI/180,u=2*Math.asin(Math.sqrt(Math.pow(Math.sin(i/2),2)+Math.cos(o)*Math.cos(a)*Math.pow(Math.sin(c/2),2)));return u*=6378.137,u=Math.round(1e4*u)/1e4},exports.filterPhone=function(t){return String(t).replace(/[^\d.]+/g,"").replace(/^\+?86/g,"").substring(0,11)},exports.formatDate=function(t,e){var r={"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),S:t.getMilliseconds()};for(var n in/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(t.getFullYear()+"").substr(4-RegExp.$1.length))),r)new RegExp("("+n+")").test(e)&&(e=e.replace(RegExp.$1,1===RegExp.$1.length?r[n]:("00"+r[n]).substr((""+r[n]).length)));return e},exports.getTimestamp=function(t){return Date.parse(new Date(t).toString())},exports.getType=function(t){var e=Object.prototype.toString;return t instanceof Element?"element":{"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regExp","[object Undefined]":"undefined","[object Null]":"null","[object Object]":"object"}[e.call(t)]},exports.hidePhone=function(t){return t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")},exports.isArray=function(t){return t instanceof Array||"[object Array]"===Object.prototype.toString.call(t)},exports.isEmpty=function(t){return null==t||""===t},exports.isNumber=function(t){return t instanceof Number||"[object Number]"===Object.prototype.toString.call(t)},exports.random=function(t,e){return Math.floor(Math.random()*(e-t+1))+t},exports.randomSort=function(t){return t.sort((function(){return Math.random()-.5}))},exports.uuid=function(t,e){void 0===t&&(t=8),void 0===e&&(e=16);var r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],o=0;if(e=e||r.length,t)for(o=0;o<t;o++)n[o]=r[0|Math.random()*e];else{var a=void 0;for(n[8]=n[13]=n[18]=n[23]="-",n[14]="4",o=0;o<36;o++)n[o]||(a=0|16*Math.random(),n[o]=r[19===o?3&a|8:a])}return n.join("")};

@@ -1,240 +0,1 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.utilsCommon = {}));
})(this, (function (exports) { 'use strict';
var createQueryString = function createQueryString(options) {
return Object.keys(options).filter(function (key) {
return options[key] !== undefined && options[key] !== "" && ["pfx", "apiKey", "sign", "key"].indexOf(key) < 0;
}).sort().map(function (key) {
return key + "=" + options[key];
}).join("&");
};
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
/**
* Deep clones an object.
* @param obj The object to deep clone.
* @param options Options for deep cloning.
* @returns The deep cloned object.
*/
var deepClone = function deepClone(obj, options) {
if (obj === null || _typeof(obj) !== "object") {
return obj;
}
var preserveNonEnumerable = (options === null || options === void 0 ? void 0 : options.preserveNonEnumerable) || false;
var copy = Array.isArray(obj) ? [] : {};
if (!preserveNonEnumerable) {
var allPropertyKeys = Object.keys(obj).concat(Object.getOwnPropertySymbols(obj));
for (var _i = 0, allPropertyKeys_1 = allPropertyKeys; _i < allPropertyKeys_1.length; _i++) {
var key = allPropertyKeys_1[_i];
if (Object.prototype.propertyIsEnumerable.call(obj, key)) {
copy[key] = deepClone(obj[key], options);
}
}
} else {
for (var key in obj) {
if (Object.prototype.propertyIsEnumerable.call(obj, key) || preserveNonEnumerable) {
copy[key] = deepClone(obj[key], options);
}
}
}
return copy;
};
var distance = function distance(lat1, lng1, lat2, lng2) {
var radLat1 = lat1 * Math.PI / 180.0;
var radLat2 = lat2 * Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
// TODO 数值单位:米 => Math.round(s * 10000) / 10
return s; //返回数值单位:公里
};
/**
* @method 过滤手机号空格以及+86
* @param {Number} tel 手机号
*/
var filterPhone = function filterPhone(tel) {
var phone = String(tel).replace(/[^\d.]+/g, "").replace(/^\+?86/g, "").substring(0, 11);
return phone;
};
/**
* @param date Date类型 new Date()
* @param fmt 格式化类型 yyyy-MM-dd hh:mm:ss
* @returns 时间字符串 2022-03-29 17:22:30
*/
function formatDate(date, fmt) {
var o = {
"M+": date.getMonth() + 1,
"d+": date.getDate(),
"h+": date.getHours(),
"m+": date.getMinutes(),
"s+": date.getSeconds(),
"q+": Math.floor((date.getMonth() + 3) / 3),
S: date.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1,
// eslint-disable-next-line
// @ts-ignore
RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return fmt;
}
/**
* @param dateStr 字符串格式为 2017-02-10 18:20:30
* 注意:此处月、日、时分秒、必须为2位数字,否则报错
* @returns 时间戳
*/
function getTimestamp(dateStr) {
return Date.parse(new Date(dateStr).toString());
}
/**
* @method 获取当前数据类型
* @param {*} obj
*/
var getType = function getType(obj) {
var str = Object.prototype.toString;
var map = {
"[object Boolean]": "boolean",
"[object Number]": "number",
"[object String]": "string",
"[object Function]": "function",
"[object Array]": "array",
"[object Date]": "date",
"[object RegExp]": "regExp",
"[object Undefined]": "undefined",
"[object Null]": "null",
"[object Object]": "object"
};
if (obj instanceof Element) {
return "element";
}
return map[str.call(obj)];
};
var hidePhone = function hidePhone(val) {
return val.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2");
};
/**
* 判断是否为数组
* @param input 任意值对象
* @returns boolean
*/
function isArray(input) {
return input instanceof Array || Object.prototype.toString.call(input) === "[object Array]";
}
/**
* 判断是否为空
* @param input 任意值对象
* @returns boolean
*/
function isEmpty(input) {
return typeof input === "undefined" || input === null || input === "";
}
/**
* 判断是否为数字
* @param input 任意值对象
* @returns boolean
*/
function isNumber(input) {
return input instanceof Number || Object.prototype.toString.call(input) === "[object Number]";
}
/**
* 生成数字范围内的随机数
* @param min 最小数字
* @param max 最大数字
* @returns number类型
*/
function random(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var randomSort = function randomSort(arr) {
return arr.sort(function () {
return Math.random() - 0.5;
});
};
// 生成uuid
/**
*
* @param len { number }
* @param radix { number }
* @returns { string }
*/
var uuid = function uuid(len, radix) {
if (len === void 0) {
len = 8;
}
if (radix === void 0) {
radix = 16;
}
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
var value = [];
var i = 0;
radix = radix || chars.length;
if (len) {
// Compact form
for (i = 0; i < len; i++) value[i] = chars[0 | Math.random() * radix];
} else {
// rfc4122, version 4 form
var r = void 0;
// rfc4122 requires these characters
/* eslint-disable-next-line */
value[8] = value[13] = value[18] = value[23] = "-";
value[14] = "4";
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
for (i = 0; i < 36; i++) {
if (!value[i]) {
r = 0 | Math.random() * 16;
value[i] = chars[i === 19 ? r & 0x3 | 0x8 : r];
}
}
}
return value.join("");
};
exports.createQueryString = createQueryString;
exports.deepClone = deepClone;
exports.distance = distance;
exports.filterPhone = filterPhone;
exports.formatDate = formatDate;
exports.getTimestamp = getTimestamp;
exports.getType = getType;
exports.hidePhone = hidePhone;
exports.isArray = isArray;
exports.isEmpty = isEmpty;
exports.isNumber = isNumber;
exports.random = random;
exports.randomSort = randomSort;
exports.uuid = uuid;
}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).utilsCommon={})}(this,(function(t){"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}t.createQueryString=function(t){return Object.keys(t).filter((function(e){return void 0!==t[e]&&""!==t[e]&&["pfx","apiKey","sign","key"].indexOf(e)<0})).sort().map((function(e){return e+"="+t[e]})).join("&")},t.deepClone=function t(n,r){if(null===n||"object"!==e(n))return n;var o=(null==r?void 0:r.preserveNonEnumerable)||!1,i=Array.isArray(n)?[]:{};if(o)for(var a in n)(Object.prototype.propertyIsEnumerable.call(n,a)||o)&&(i[a]=t(n[a],r));else for(var u=0,c=Object.keys(n).concat(Object.getOwnPropertySymbols(n));u<c.length;u++){var a=c[u];Object.prototype.propertyIsEnumerable.call(n,a)&&(i[a]=t(n[a],r))}return i},t.distance=function(t,e,n,r){var o=t*Math.PI/180,i=n*Math.PI/180,a=o-i,u=e*Math.PI/180-r*Math.PI/180,c=2*Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2)+Math.cos(o)*Math.cos(i)*Math.pow(Math.sin(u/2),2)));return c*=6378.137,c=Math.round(1e4*c)/1e4},t.filterPhone=function(t){return String(t).replace(/[^\d.]+/g,"").replace(/^\+?86/g,"").substring(0,11)},t.formatDate=function(t,e){var n={"M+":t.getMonth()+1,"d+":t.getDate(),"h+":t.getHours(),"m+":t.getMinutes(),"s+":t.getSeconds(),"q+":Math.floor((t.getMonth()+3)/3),S:t.getMilliseconds()};for(var r in/(y+)/.test(e)&&(e=e.replace(RegExp.$1,(t.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+r+")").test(e)&&(e=e.replace(RegExp.$1,1===RegExp.$1.length?n[r]:("00"+n[r]).substr((""+n[r]).length)));return e},t.getTimestamp=function(t){return Date.parse(new Date(t).toString())},t.getType=function(t){var e=Object.prototype.toString;return t instanceof Element?"element":{"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regExp","[object Undefined]":"undefined","[object Null]":"null","[object Object]":"object"}[e.call(t)]},t.hidePhone=function(t){return t.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")},t.isArray=function(t){return t instanceof Array||"[object Array]"===Object.prototype.toString.call(t)},t.isEmpty=function(t){return null==t||""===t},t.isNumber=function(t){return t instanceof Number||"[object Number]"===Object.prototype.toString.call(t)},t.random=function(t,e){return Math.floor(Math.random()*(e-t+1))+t},t.randomSort=function(t){return t.sort((function(){return Math.random()-.5}))},t.uuid=function(t,e){void 0===t&&(t=8),void 0===e&&(e=16);var n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),r=[],o=0;if(e=e||n.length,t)for(o=0;o<t;o++)r[o]=n[0|Math.random()*e];else{var i=void 0;for(r[8]=r[13]=r[18]=r[23]="-",r[14]="4",o=0;o<36;o++)r[o]||(i=0|16*Math.random(),r[o]=n[19===o?3&i|8:i])}return r.join("")}}));
export interface DeepCopyOptions {
/**
* Whether to preserve non-enumerable properties. Default is false.
*/
preserveNonEnumerable?: boolean;
}
/**
* Deep clones an object.
* @param obj The object to deep clone.
* @param options Options for deep cloning.
* @returns The deep cloned object.
*/
export declare const deepClone: <T>(obj: T, options?: DeepCopyOptions) => T;

5

package.json
{
"name": "@bnfe/common-utils",
"version": "1.1.1",
"version": "1.2.0",
"description": "utils-common",

@@ -16,5 +16,4 @@ "main": "dist/common-utils.js",

"scripts": {
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
"update:version": "npx bumpp --no-push --no-commit --no-tag"
"build": "rollup -c rollup.config.js --bundleConfigAsCjs"
}
}

Sorry, the diff of this file is not supported yet

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