jj-fast-utils
Version:
🚀 FE utils for anyone !
3 lines (2 loc) • 1.96 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["jj-fast-utils"]={})}(this,(function(e){"use strict";var t=e=>{const t=10**(e-1),r=10**e-1;return`${Math.floor(Math.random()*(r-t+1))+t}`};var r=e=>{const t=["零","一","二","三","四","五","六","七","八","九"],r=["","十","百","千","万","十","百","千","亿","十","百","千","万","十","百","千","亿"];if(!e||isNaN(e))return"零";const o=e.toString().split("");let a="";for(let e=0;e<o.length;e++){const n=o.length-1-e;a=r[e]+a;const s=o[n];a=t[Number(s)]+a}return a=a.replace(/零([千百十])/g,"零").replace(/十零/g,"十"),a=a.replace(/零+/g,"零"),a=a.replace(/零亿/g,"亿").replace(/零万/g,"万"),a=a.replace(/亿万/g,"亿"),a=a.replace(/零+$/,""),a=a.replace(/^一十/g,"十"),a};var o=e=>{if("string"!=typeof e)throw new Error("color has to be type of `string`");if("#"===e.substr(0,1))return{hex:e,alpha:1};const t=e.replace(/\s+/g,""),r=/(.*?)rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([01]|1.0*|0?\.(\d*)))?\)/.exec(t);if(!r)throw new Error(`given color (${e}) isn't a valid rgb or rgba color`);const o=parseInt(r[3],10),a=parseInt(r[4],10),n=parseInt(r[5],10);let s=r[6]?/[\d.]+/.exec(r[6])[0]:"1";const i=(n|a<<8|o<<16|1<<24).toString(16).slice(1);return"."===s.substr(0,1)&&(s=parseFloat(`0${s}`)),s=parseFloat(Math.round(100*s))/100,{hex:`#${i.toString(16)}`,alpha:s}};var a=e=>{const t=Object.prototype.toString.call(e).split(" ")[1];return t.substring(0,t.length-1).toLowerCase()};var n=e=>/^\d{6}$/.test(`${e}`);var s=e=>/^[\w.!#$%&’*+/=?^`{|}~-]+@[a-zA-Z\d-]+(?:\.[a-zA-Z\d-]+)*$/.test(e);var i=e=>!e;var l=e=>{try{return JSON.parse(e),!0}catch(e){return!1}};e.generateNumberStr=t,e.getDataType=a,e.isCode=n,e.isEmail=s,e.isEmpty=i,e.isJSON=l,e.numberToChinese=r,e.rgbTohex=o}));
//# sourceMappingURL=node.umd.js.map