New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

funclab

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

funclab - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

2

dist/index.cjs.js

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

"use strict";function e(e){return("number"==typeof e||"string"==typeof e)&&(!(!e&&0!==e&&"0"!==e)&&(e=e.toString().trim(),!isNaN(e)&&isFinite(e)&&(e.match(/\./g)||[]).length<=1))}function r(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD HH:mm:ss",t=new Date(e);if(isNaN(t))throw new Error("Invalid date format. Please use a valid date string.");var n=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),l=String(t.getHours()%12||12).padStart(2,"0"),u=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0"),p=String(t.getMilliseconds()).padStart(3,"0"),s=t.getHours()>=12?"PM":"AM";return r.replace("YYYY",n).replace("MM",a).replace("DD",i).replace("HH",o).replace("hh",l).replace("mm",u).replace("ss",c).replace("SSS",p).replace("A",s)}function t(e,t){var n=new Date(r(e,"YYYY-MM-DD")),a=new Date(r(t,"YYYY-MM-DD"));if(isNaN(n)||isNaN(a))throw new Error("Invalid date format. Please use a valid date string.");return Math.abs(a-n)/864e5}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function a(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function i(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function o(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?i(Object(t),!0).forEach((function(r){a(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function l(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i,o,l=[],u=!0,c=!1;try{if(i=(t=t.call(e)).next,0===r);else for(;!(u=(n=i.call(t)).done)&&(l.push(n.value),l.length!==r);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=t.return&&(o=t.return(),Object(o)!==o))return}finally{if(c)throw a}}return l}}(e,r)||p(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function p(e,r){if(e){if("string"==typeof e)return n(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}function s(e){var r,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new WeakMap;if(null==e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Map){var n=new Map;return e.forEach((function(e,r){n.set(r,s(e,t))})),n}if(e instanceof Set){var a=new Set;return e.forEach((function(e){a.add(s(e,t))})),a}if("object"!==c(e))return e;if(t.has(e))return t.get(e);for(var i in r=Array.isArray(e)?[]:{},t.set(e,r),e)e.hasOwnProperty(i)&&(r[i]=s(e[i],t));return r}function d(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=o({childrenKeyMapping:{children:"children"},extraFields:["parentId","path","level"],extraFieldsMappings:{},nodeKey:"id"},arguments.length>2?arguments[2]:void 0),n=t.childrenKeyMapping,a=t.extraFields,i=t.extraFieldsMappings,p=t.nodeKey;if("object"!==c(e)||null===e)throw new TypeError("The 'tree' parameter should be an object or array representing the tree structure.");if("object"!==c(r)||null===r||Array.isArray(r))throw new TypeError("The 'fieldMappings' parameter should be an object mapping original field names to new field names.");if("object"!==c(n)||Array.isArray(n)||1!==Object.keys(n).length)throw new TypeError("The 'childrenKeyMapping' parameter should be an object with a single key-value pair for original and target child keys.");if(!Array.isArray(a)||!a.every((function(e){return"string"==typeof e})))throw new TypeError("The 'extraFields' parameter should be an array of strings representing extraFieldsal properties to add.");if("object"!==c(i)||Array.isArray(i))throw new TypeError("The 'extraFieldsMappings' parameter should be an object mapping extraFieldsal property names to new property names.");var d=l(Object.entries(n)[0],2),f=d[0],y=d[1],h=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,c=o({},s(e));if(null!=a&&a.includes("level")){var d=(null==i?void 0:i.level)||"level";c[d]=t}var g=[].concat(u(n),[c[p]]);if(null!=a&&a.includes("path")){var v=(null==i?void 0:i.path)||"path";c[v]=g}if(null!=a&&a.includes("parentId")){var m=(null==i?void 0:i.parentId)||"parentId";c[m]=l}return c[y]=Array.isArray(e[f])&&e[f].length?e[f].map((function(e){return h(e,t+1,g,c[p])})):[],f!==y&&delete c[f],c=Object.keys(r).reduce((function(t,n){return void 0!==e[n]&&(t[r[n]]=s(e[n]),delete t[n]),t}),c)};return(Array.isArray(e)?e:[e]).map((function(e){return h(e)}))}t(new Date("2024-01-01"),new Date("2024-01-10"));var f=d([{name:"节点1",id:1,children:[{name:"节点1-1",id:2}]},{name:"节点2",id:3}],{name:"label",id:"value"},{nodeKey:"id",childrenKeyMapping:{children:"items"},extraFields:["parentId","path","level"],extraFieldsMappings:{parentId:"pid",path:"idPaths",level:"depth"}});console.log(JSON.stringify(f,null,2));exports.capitalize=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},exports.cloneDeep=s,exports.daysBetweenDates=t,exports.formatCurrency=function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=r;if(!e(i))return"Invalid number";var o=Math.pow(10,t),u=l((Math.round(i*o)/o).toFixed(t).split("."),2),c=u[0],p=u[1],s=n?c.replace(/\B(?=(\d{3})+(?!\d))/g,","):c,d=a&&p?p.replace(/\B(?=(\d{3})+(?!\d))/g,","):p;return void 0!==d?"".concat(s,".").concat(d):s},exports.formatDate=r,exports.formatTree=d,exports.guid=function(){for(var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t="",n=1;n<=32;n++)t+=Math.floor(16*Math.random()).toString(16),e&&[8,12,16,20].includes(n)&&(t+="-");return r?t.toUpperCase():t},exports.isNumeric=e,exports.randomInteger=function(e,r){return Math.floor(Math.random()*(r-e+1))+e},exports.reverseString=function(e){return e.split("").reverse().join("")},exports.roundTo=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=Number(e);return isNaN(t)?"Invalid number":t.toFixed(r)};
"use strict";function e(e){return("number"==typeof e||"string"==typeof e)&&(!(!e&&0!==e&&"0"!==e)&&(e=e.toString().trim(),!isNaN(e)&&isFinite(e)&&(e.match(/\./g)||[]).length<=1))}function r(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD HH:mm:ss",t=new Date(e);if(isNaN(t))throw new Error("Invalid date format. Please use a valid date string.");var n=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),i=String(t.getHours()).padStart(2,"0"),l=String(t.getHours()%12||12).padStart(2,"0"),u=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0"),s=String(t.getMilliseconds()).padStart(3,"0"),p=t.getHours()>=12?"PM":"AM";return r.replace("YYYY",n).replace("MM",a).replace("DD",o).replace("HH",i).replace("hh",l).replace("mm",u).replace("ss",c).replace("SSS",s).replace("A",p)}function t(e,t){var n=new Date(r(e,"YYYY-MM-DD")),a=new Date(r(t,"YYYY-MM-DD"));if(isNaN(n)||isNaN(a))throw new Error("Invalid date format. Please use a valid date string.");return Math.abs(a-n)/864e5}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function a(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?o(Object(t),!0).forEach((function(r){a(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function l(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,o,i,l=[],u=!0,c=!1;try{if(o=(t=t.call(e)).next,0===r);else for(;!(u=(n=o.call(t)).done)&&(l.push(n.value),l.length!==r);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw a}}return l}}(e,r)||s(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||s(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function s(e,r){if(e){if("string"==typeof e)return n(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}function p(e){var r,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new WeakMap;if(null==e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Map){var n=new Map;return e.forEach((function(e,r){n.set(r,p(e,t))})),n}if(e instanceof Set){var a=new Set;return e.forEach((function(e){a.add(p(e,t))})),a}if("object"!==c(e))return e;if(t.has(e))return t.get(e);for(var o in r=Array.isArray(e)?[]:{},t.set(e,r),e)e.hasOwnProperty(o)&&(r[o]=p(e[o],t));return r}t(new Date("2024-01-01"),new Date("2024-01-10"));exports.capitalize=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},exports.cloneDeep=p,exports.daysBetweenDates=t,exports.formatCurrency=function(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],o=r;if(!e(o))return"Invalid number";var i=Math.pow(10,t),u=l((Math.round(o*i)/i).toFixed(t).split("."),2),c=u[0],s=u[1],p=n?c.replace(/\B(?=(\d{3})+(?!\d))/g,","):c,f=a&&s?s.replace(/\B(?=(\d{3})+(?!\d))/g,","):s;return void 0!==f?"".concat(p,".").concat(f):p},exports.formatDate=r,exports.formatTree=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=i({childrenKeyMapping:{children:"children"},extraFields:["parentId","path","level"],extraFieldsMappings:{},nodeKey:"id"},arguments.length>2?arguments[2]:void 0),n=t.childrenKeyMapping,a=t.extraFields,o=t.extraFieldsMappings,s=t.nodeKey;if("object"!==c(e)||null===e)throw new TypeError("The 'tree' parameter should be an object or array representing the tree structure.");if("object"!==c(r)||null===r||Array.isArray(r))throw new TypeError("The 'fieldMappings' parameter should be an object mapping original field names to new field names.");if("object"!==c(n)||Array.isArray(n)||1!==Object.keys(n).length)throw new TypeError("The 'childrenKeyMapping' parameter should be an object with a single key-value pair for original and target child keys.");if(!Array.isArray(a)||!a.every((function(e){return"string"==typeof e})))throw new TypeError("The 'extraFields' parameter should be an array of strings representing extraFieldsal properties to add.");if("object"!==c(o)||Array.isArray(o))throw new TypeError("The 'extraFieldsMappings' parameter should be an object mapping extraFieldsal property names to new property names.");var f=l(Object.entries(n)[0],2),d=f[0],y=f[1],g=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,c=i({},p(e));if(null!=a&&a.includes("level")){var f=(null==o?void 0:o.level)||"level";c[f]=t}var h=[].concat(u(n),[c[s]]);if(null!=a&&a.includes("path")){var v=(null==o?void 0:o.path)||"path";c[v]=h}if(null!=a&&a.includes("parentId")){var b=(null==o?void 0:o.parentId)||"parentId";c[b]=l}return c[y]=Array.isArray(e[d])&&e[d].length?e[d].map((function(e){return g(e,t+1,h,c[s])})):[],d!==y&&delete c[d],c=Object.keys(r).reduce((function(t,n){return void 0!==e[n]&&(t[r[n]]=p(e[n]),delete t[n]),t}),c)};return(Array.isArray(e)?e:[e]).map((function(e){return g(e)}))},exports.guid=function(){for(var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t="",n=1;n<=32;n++)t+=Math.floor(16*Math.random()).toString(16),e&&[8,12,16,20].includes(n)&&(t+="-");return r?t.toUpperCase():t},exports.isNumeric=e,exports.randomInteger=function(e,r){return Math.floor(Math.random()*(r-e+1))+e},exports.reverseString=function(e){return e.split("").reverse().join("")},exports.roundTo=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=Number(e);return isNaN(t)?"Invalid number":t.toFixed(r)};

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

function e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function r(e){return e.split("").reverse().join("")}function t(e){return("number"==typeof e||"string"==typeof e)&&(!(!e&&0!==e&&"0"!==e)&&(e=e.toString().trim(),!isNaN(e)&&isFinite(e)&&(e.match(/\./g)||[]).length<=1))}function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD HH:mm:ss",t=new Date(e);if(isNaN(t))throw new Error("Invalid date format. Please use a valid date string.");var n=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),l=String(t.getHours()%12||12).padStart(2,"0"),u=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0"),p=String(t.getMilliseconds()).padStart(3,"0"),s=t.getHours()>=12?"PM":"AM";return r.replace("YYYY",n).replace("MM",a).replace("DD",i).replace("HH",o).replace("hh",l).replace("mm",u).replace("ss",c).replace("SSS",p).replace("A",s)}function a(e,r){var t=new Date(n(e,"YYYY-MM-DD")),a=new Date(n(r,"YYYY-MM-DD"));if(isNaN(t)||isNaN(a))throw new Error("Invalid date format. Please use a valid date string.");return Math.abs(a-t)/864e5}function i(e,r){return Math.floor(Math.random()*(r-e+1))+e}function o(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=Number(e);return isNaN(t)?"Invalid number":t.toFixed(r)}function l(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function u(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function c(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function p(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?c(Object(t),!0).forEach((function(r){u(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):c(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function s(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i,o,l=[],u=!0,c=!1;try{if(i=(t=t.call(e)).next,0===r);else for(;!(u=(n=i.call(t)).done)&&(l.push(n.value),l.length!==r);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=t.return&&(o=t.return(),Object(o)!==o))return}finally{if(c)throw a}}return l}}(e,r)||y(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){return function(e){if(Array.isArray(e))return l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||y(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}function y(e,r){if(e){if("string"==typeof e)return l(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?l(e,r):void 0}}function h(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=e;if(!t(i))return"Invalid number";var o=Math.pow(10,r),l=s((Math.round(i*o)/o).toFixed(r).split("."),2),u=l[0],c=l[1],p=n?u.replace(/\B(?=(\d{3})+(?!\d))/g,","):u,d=a&&c?c.replace(/\B(?=(\d{3})+(?!\d))/g,","):c;return void 0!==d?"".concat(p,".").concat(d):p}function g(e){var r,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new WeakMap;if(null==e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Map){var n=new Map;return e.forEach((function(e,r){n.set(r,g(e,t))})),n}if(e instanceof Set){var a=new Set;return e.forEach((function(e){a.add(g(e,t))})),a}if("object"!==f(e))return e;if(t.has(e))return t.get(e);for(var i in r=Array.isArray(e)?[]:{},t.set(e,r),e)e.hasOwnProperty(i)&&(r[i]=g(e[i],t));return r}function v(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=p({childrenKeyMapping:{children:"children"},extraFields:["parentId","path","level"],extraFieldsMappings:{},nodeKey:"id"},arguments.length>2?arguments[2]:void 0),n=t.childrenKeyMapping,a=t.extraFields,i=t.extraFieldsMappings,o=t.nodeKey;if("object"!==f(e)||null===e)throw new TypeError("The 'tree' parameter should be an object or array representing the tree structure.");if("object"!==f(r)||null===r||Array.isArray(r))throw new TypeError("The 'fieldMappings' parameter should be an object mapping original field names to new field names.");if("object"!==f(n)||Array.isArray(n)||1!==Object.keys(n).length)throw new TypeError("The 'childrenKeyMapping' parameter should be an object with a single key-value pair for original and target child keys.");if(!Array.isArray(a)||!a.every((function(e){return"string"==typeof e})))throw new TypeError("The 'extraFields' parameter should be an array of strings representing extraFieldsal properties to add.");if("object"!==f(i)||Array.isArray(i))throw new TypeError("The 'extraFieldsMappings' parameter should be an object mapping extraFieldsal property names to new property names.");var l=s(Object.entries(n)[0],2),u=l[0],c=l[1],y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,s=p({},g(e));if(null!=a&&a.includes("level")){var f=(null==i?void 0:i.level)||"level";s[f]=t}var h=[].concat(d(n),[s[o]]);if(null!=a&&a.includes("path")){var v=(null==i?void 0:i.path)||"path";s[v]=h}if(null!=a&&a.includes("parentId")){var b=(null==i?void 0:i.parentId)||"parentId";s[b]=l}return s[c]=Array.isArray(e[u])&&e[u].length?e[u].map((function(e){return y(e,t+1,h,s[o])})):[],u!==c&&delete s[u],s=Object.keys(r).reduce((function(t,n){return void 0!==e[n]&&(t[r[n]]=g(e[n]),delete t[n]),t}),s)};return(Array.isArray(e)?e:[e]).map((function(e){return y(e)}))}a(new Date("2024-01-01"),new Date("2024-01-10"));var b=v([{name:"节点1",id:1,children:[{name:"节点1-1",id:2}]},{name:"节点2",id:3}],{name:"label",id:"value"},{nodeKey:"id",childrenKeyMapping:{children:"items"},extraFields:["parentId","path","level"],extraFieldsMappings:{parentId:"pid",path:"idPaths",level:"depth"}});console.log(JSON.stringify(b,null,2));var m=function(){for(var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t="",n=1;n<=32;n++)t+=Math.floor(16*Math.random()).toString(16),e&&[8,12,16,20].includes(n)&&(t+="-");return r?t.toUpperCase():t};export{e as capitalize,g as cloneDeep,a as daysBetweenDates,h as formatCurrency,n as formatDate,v as formatTree,m as guid,t as isNumeric,i as randomInteger,r as reverseString,o as roundTo};
function e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function r(e){return e.split("").reverse().join("")}function t(e){return("number"==typeof e||"string"==typeof e)&&(!(!e&&0!==e&&"0"!==e)&&(e=e.toString().trim(),!isNaN(e)&&isFinite(e)&&(e.match(/\./g)||[]).length<=1))}function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"YYYY-MM-DD HH:mm:ss",t=new Date(e);if(isNaN(t))throw new Error("Invalid date format. Please use a valid date string.");var n=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),o=String(t.getHours()).padStart(2,"0"),l=String(t.getHours()%12||12).padStart(2,"0"),u=String(t.getMinutes()).padStart(2,"0"),c=String(t.getSeconds()).padStart(2,"0"),p=String(t.getMilliseconds()).padStart(3,"0"),f=t.getHours()>=12?"PM":"AM";return r.replace("YYYY",n).replace("MM",a).replace("DD",i).replace("HH",o).replace("hh",l).replace("mm",u).replace("ss",c).replace("SSS",p).replace("A",f)}function a(e,r){var t=new Date(n(e,"YYYY-MM-DD")),a=new Date(n(r,"YYYY-MM-DD"));if(isNaN(t)||isNaN(a))throw new Error("Invalid date format. Please use a valid date string.");return Math.abs(a-t)/864e5}function i(e,r){return Math.floor(Math.random()*(r-e+1))+e}function o(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=Number(e);return isNaN(t)?"Invalid number":t.toFixed(r)}function l(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function u(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function c(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function p(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?c(Object(t),!0).forEach((function(r){u(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):c(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function f(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i,o,l=[],u=!0,c=!1;try{if(i=(t=t.call(e)).next,0===r);else for(;!(u=(n=i.call(t)).done)&&(l.push(n.value),l.length!==r);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=t.return&&(o=t.return(),Object(o)!==o))return}finally{if(c)throw a}}return l}}(e,r)||y(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e){return function(e){if(Array.isArray(e))return l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||y(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},d(e)}function y(e,r){if(e){if("string"==typeof e)return l(e,r);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?l(e,r):void 0}}function h(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=e;if(!t(i))return"Invalid number";var o=Math.pow(10,r),l=f((Math.round(i*o)/o).toFixed(r).split("."),2),u=l[0],c=l[1],p=n?u.replace(/\B(?=(\d{3})+(?!\d))/g,","):u,s=a&&c?c.replace(/\B(?=(\d{3})+(?!\d))/g,","):c;return void 0!==s?"".concat(p,".").concat(s):p}function g(e){var r,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new WeakMap;if(null==e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Map){var n=new Map;return e.forEach((function(e,r){n.set(r,g(e,t))})),n}if(e instanceof Set){var a=new Set;return e.forEach((function(e){a.add(g(e,t))})),a}if("object"!==d(e))return e;if(t.has(e))return t.get(e);for(var i in r=Array.isArray(e)?[]:{},t.set(e,r),e)e.hasOwnProperty(i)&&(r[i]=g(e[i],t));return r}function v(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=p({childrenKeyMapping:{children:"children"},extraFields:["parentId","path","level"],extraFieldsMappings:{},nodeKey:"id"},arguments.length>2?arguments[2]:void 0),n=t.childrenKeyMapping,a=t.extraFields,i=t.extraFieldsMappings,o=t.nodeKey;if("object"!==d(e)||null===e)throw new TypeError("The 'tree' parameter should be an object or array representing the tree structure.");if("object"!==d(r)||null===r||Array.isArray(r))throw new TypeError("The 'fieldMappings' parameter should be an object mapping original field names to new field names.");if("object"!==d(n)||Array.isArray(n)||1!==Object.keys(n).length)throw new TypeError("The 'childrenKeyMapping' parameter should be an object with a single key-value pair for original and target child keys.");if(!Array.isArray(a)||!a.every((function(e){return"string"==typeof e})))throw new TypeError("The 'extraFields' parameter should be an array of strings representing extraFieldsal properties to add.");if("object"!==d(i)||Array.isArray(i))throw new TypeError("The 'extraFieldsMappings' parameter should be an object mapping extraFieldsal property names to new property names.");var l=f(Object.entries(n)[0],2),u=l[0],c=l[1],y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,f=p({},g(e));if(null!=a&&a.includes("level")){var d=(null==i?void 0:i.level)||"level";f[d]=t}var h=[].concat(s(n),[f[o]]);if(null!=a&&a.includes("path")){var v=(null==i?void 0:i.path)||"path";f[v]=h}if(null!=a&&a.includes("parentId")){var b=(null==i?void 0:i.parentId)||"parentId";f[b]=l}return f[c]=Array.isArray(e[u])&&e[u].length?e[u].map((function(e){return y(e,t+1,h,f[o])})):[],u!==c&&delete f[u],f=Object.keys(r).reduce((function(t,n){return void 0!==e[n]&&(t[r[n]]=g(e[n]),delete t[n]),t}),f)};return(Array.isArray(e)?e:[e]).map((function(e){return y(e)}))}a(new Date("2024-01-01"),new Date("2024-01-10"));var b=function(){for(var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t="",n=1;n<=32;n++)t+=Math.floor(16*Math.random()).toString(16),e&&[8,12,16,20].includes(n)&&(t+="-");return r?t.toUpperCase():t};export{e as capitalize,g as cloneDeep,a as daysBetweenDates,h as formatCurrency,n as formatDate,v as formatTree,b as guid,t as isNumeric,i as randomInteger,r as reverseString,o as roundTo};
{
"name": "funclab",
"version": "0.0.9",
"version": "0.0.10",
"main": "dist/index.cjs.js",

@@ -5,0 +5,0 @@ "module": "dist/index.esm.js",

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