UNPKG

@yuanjili/js-es-c

Version:

js工具包

1 lines 2.01 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringToBoolean=exports.StringToNumber=exports.urlToArr=exports.uuid=exports.uid=void 0,exports.strCut=strCut,exports.strSpace=strSpace,exports.strHasKey=strHasKey,exports.isString=isString,exports.byteLength=byteLength,exports.replaceString=replaceString;var _arrFun=require("./arrFun");function strCut(a,b){for(var c=void 0,d=0,e=/[^\x00-\xff]/,f="",g=0;g<a.length&&d<2*b-1;g++)c=a.substr(g,1),null==e.exec(c)?++d:d+=2,f+=c;return f+"..."}function strSpace(a){var b=a.replace(/(^\s+)|(\s+$)/g,"");return b.replace(/\s/g,"")}function strHasKey(a,b){return"string"==typeof a?-1!==a.indexOf(b):(console.log("\u9519\u8BEF\uFF1A\u8FD9\u4E0D\u662F\u4E00\u4E2A\u5B57\u7B26\u4E32"),!1)}var uid=exports.uid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=0|16*Math.random(),c="x"==a?b:8|3&b;return c.toString(16)})},uuid=exports.uuid=function(){try{if("undefined"!=typeof crypto&&crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&crypto.getRandomValues)return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,function(a){return(a^crypto.getRandomValues(new Uint8Array(1))[0]&15>>a/4).toString(16)})}catch(a){console.warn("Crypto API not available, using fallback")}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=0|16*Math.random(),c="x"===a?b:8|3&b;return c.toString(16)})},urlToArr=exports.urlToArr=function(a){return a?(0,_arrFun.stringArrAddValue)((0,_arrFun.arrDelNull)(a.split("/"))):[]};function isString(a){return"[object String]"==Object.prototype.toString.call(a)}var StringToNumber=exports.StringToNumber=function(a){return parseInt(a)},StringToBoolean=exports.StringToBoolean=function(a){return!("true"!==a)};function byteLength(a){for(var b,c=a.length,d=a.length-1;0<=d;d--)b=a.charCodeAt(d),127<b&&2047>=b?c++:2047<b&&65535>=b&&(c+=2),56320<=b&&57343>=b&&d--;return c}function replaceString(a,b,c){return a.split(b).join(c)}