@sumor/utils
Advanced tools
Comparing version 11.0.0 to 11.0.1
@@ -1,1 +0,1 @@ | ||
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){global.sumor_output=r(2)},function(e,t,r){const n=r(3),o=r(10),i=new n,a=new o;e.exports={file:i,basic:a}},function(e,t,r){const n=r(4),o=r(5),i=r(6),a=r(7),u=r(8),s=r(9);e.exports=class{constructor(){}normalize(e){let t=a.normalize(e);return t=t.replace(/\\/g,"/")}async download(e,t){await new Promise(function(r){u(e).pipe(n.createWriteStream(t)).on("close",function(){r()})})}async find(e,t){return t=t||{},await new Promise(function(r){s(e,t,function(e,t){for(let e in t)t[e]=a.normalize(t[e]),t[e]=t[e].replace(/\\/g,"/");r(t)})})}async zip(e,t,r){return await new Promise(function(i,a){let u=n.createWriteStream(t),s=o("zip",{zlib:{level:9}});u.on("close",function(){i()}),s.pipe(u),s.glob("**",{cwd:e,ignore:r||[]}),s.finalize()})}async unzip(e,t){return e=a.normalize(e),await new Promise(function(r,n){i(e,{dir:t},function(e){r()})})}async exist(e){return await new Promise(function(t){n.access(e,function(e){t(!e)})})}async isDirectory(e){return n.statSync(e).isDirectory()}async move(e,t){await n.move(e,t)}async delete(e){await n.remove(e)}async ensureFile(e){await n.ensureFile(e)}async ensureDir(e){await n.ensureDir(e)}async copy(e,t,r){await n.copy(e,t,r)}async writeFile(e,t){return await new Promise((r,o)=>{n.writeFile(e,t,e=>{e?o(e):r()})})}async appendFile(e,t){return await new Promise((r,o)=>{n.appendFile(e,t,e=>{e?o(e):r()})})}async readFile(e,t){if(await this.exist(e))return await new Promise(function(r){n.readFile(e,t,(e,t)=>{r(t)})})}async readJson(e){return await n.readJson(e)}async getExt(e){return a.extname(e)}}},function(e,t){e.exports=require("fs-extra")},function(e,t){e.exports=require("archiver")},function(e,t){e.exports=require("extract-zip")},function(e,t){e.exports=require("path")},function(e,t){e.exports=require("download")},function(e,t){e.exports=require("glob")},function(e,t,r){const n=r(11),o=r(12),i=r(13);e.exports=class{constructor(){this.triggerQueue={}}uuid(){return o.v4().replace(/-/g,"")}md5(e){const t=n.createHash("md5");return t.update(e),t.digest("hex")}async qrcode(e){let t={errorCorrectionLevel:"H",rendererOpts:{quality:.8},color:{light:"#f8f8f8"}};return await new Promise(function(r,n){i.toDataURL(e,t,function(e,t){e?n(e):r(t)})})}getTimestamp(){return Math.round(new Date/1e3)}async delay(e){return e=e||1e3,await new Promise(function(t){setTimeout(function(){t()},e)})}formatTime(e,t,r){if("number"==typeof e&&(e=new Date(1e3*e)),"number"!=typeof(r=r||-(new Date).getTimezoneOffset()))throw{code:"NOT_SUPPORT_STRING_TIMEZORE",message:"暂不支持字符串格式时区,请输入分钟数"};let n=e.getTime();const o={"M+":(e=new Date(n+=60*r*1e3)).getUTCMonth()+1,"d+":e.getUTCDate(),"W+":function(e){switch(e.getUTCDay()){case 0:return"日";case 1:return"一";case 2:return"二";case 3:return"三";case 4:return"四";case 5:return"五";case 6:return"六"}}(e),"h+":e.getUTCHours(),"m+":e.getUTCMinutes(),"s+":e.getUTCSeconds(),"q+":Math.floor((e.getUTCMonth()+3)/3),S:("00"+e.getUTCMilliseconds()).slice(-3)};for(var i in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getUTCFullYear()+"").substr(4-RegExp.$1.length))),o)new RegExp("("+i+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?o[i]:("00"+o[i]).substr((""+o[i]).length)));return t}random(e,t){const r=(t||"ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789!@#$%^&*()_+-=").split("");let n="";for(let t=0;t<e;t++){n+=r[Math.floor(Math.random()*r.length)]}return n}toCamelCase(e,t,r){t=t||"-";let n=(e=e.toLowerCase()).split(t);e="";for(let t in n){let r=n[t];e+=r.replace(r[0],r[0].toUpperCase())}return r&&(e=e.replace(e[0],e[0].toLowerCase())),e}fromCamelCase(e,t){t=t||"-";const r=[];for(let t=0;t<e.length;t++){const o=e.charAt(t),i=o.toLowerCase();0===r.length?r.push(i):((n=o)>="A"&&n<="Z"&&r.push(""),r[r.length-1]=r[r.length-1]+=i)}var n;return r.join(t)}trigger(e){const t=this.uuid(),r=this.triggerQueue;return async()=>{if(r[t]||(r[t]={running:!1,again:!1}),r[t].running)r[t].again=!0;else{r[t].running=!0;const n=async()=>{await e(),r[t].again?(r[t].again=!1,await n()):delete r[t]};await n()}}}}},function(e,t){e.exports=require("crypto")},function(e,t){e.exports=require("uuid")},function(e,t){e.exports=require("qrcode")}]),global.dynamicRequire=require;var sumor_output=global.sumor_output;delete global.sumor_output,module.exports=sumor_output; | ||
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){global.sumor_output=r(2)},function(e,t,r){const n=r(3),o=r(10),i=new n,a=new o;e.exports={file:i,basic:a}},function(e,t,r){const n=r(4),o=r(5),i=r(6),a=r(7),u=r(8),s=r(9);e.exports=class{constructor(){}normalize(e){let t=a.normalize(e);return t=t.replace(/\\/g,"/")}async download(e,t){await new Promise(function(r){u(e).pipe(n.createWriteStream(t)).on("close",function(){r()})})}async find(e,t){return t=t||{},await new Promise(function(r){s(e,t,function(e,t){for(let e in t)t[e]=a.normalize(t[e]),t[e]=t[e].replace(/\\/g,"/");r(t)})})}async zip(e,t,r){return await new Promise(function(i,a){let u=n.createWriteStream(t),s=o("zip",{zlib:{level:9}});u.on("close",function(){i()}),s.pipe(u),s.glob("**",{cwd:e,ignore:r||[]}),s.finalize()})}async unzip(e,t){return e=a.normalize(e),await new Promise(function(r,n){i(e,{dir:t},function(e){r()})})}async exist(e){return await new Promise(function(t){n.access(e,function(e){t(!e)})})}async isDirectory(e){return n.statSync(e).isDirectory()}async move(e,t){await n.move(e,t)}async delete(e){await n.remove(e)}async ensureFile(e){await n.ensureFile(e)}async ensureDir(e){await n.ensureDir(e)}async copy(e,t,r){await n.copy(e,t,r)}async writeFile(e,t){return await new Promise((r,o)=>{n.writeFile(e,t,e=>{e?o(e):r()})})}async appendFile(e,t){return await new Promise((r,o)=>{n.appendFile(e,t,e=>{e?o(e):r()})})}async readFile(e,t){if(await this.exist(e))return await new Promise(function(r){n.readFile(e,t,(e,t)=>{r(t)})})}async readJson(e){return await n.readJson(e)}async getExt(e){return a.extname(e)}}},function(e,t){e.exports=require("fs-extra")},function(e,t){e.exports=require("archiver")},function(e,t){e.exports=require("extract-zip")},function(e,t){e.exports=require("path")},function(e,t){e.exports=require("download")},function(e,t){e.exports=require("glob")},function(e,t,r){const n=r(11),o=r(12),i=r(13);e.exports=class{constructor(){this.triggerQueue={}}uuid(){return o.v4().replace(/-/g,"")}md5(e){const t=n.createHash("md5");return t.update(e),t.digest("hex")}async qrcode(e){let t={errorCorrectionLevel:"H",rendererOpts:{quality:.8},color:{light:"#f8f8f8"}};return await new Promise(function(r,n){i.toDataURL(e,t,function(e,t){e?n(e):r(t)})})}getTimestamp(){return Math.round((new Date).getTime()/1e3)}async delay(e){return e=e||1e3,await new Promise(function(t){setTimeout(function(){t()},e)})}formatTime(e,t,r){let n;if(n="number"==typeof e?1e3*e:e.getTime(),"number"!=typeof(r=void 0!==r?r:-(new Date).getTimezoneOffset()))throw{code:"NOT_SUPPORT_STRING_TIMEZORE",message:"暂不支持字符串格式时区,请输入分钟数"};n+=60*r*1e3;const o=new Date(n),i={"M+":o.getUTCMonth()+1,"d+":o.getUTCDate(),"W+":function(e){switch(e.getUTCDay()){case 0:return"日";case 1:return"一";case 2:return"二";case 3:return"三";case 4:return"四";case 5:return"五";case 6:return"六"}}(o),"h+":o.getUTCHours(),"m+":o.getUTCMinutes(),"s+":o.getUTCSeconds(),"q+":Math.floor((o.getUTCMonth()+3)/3),S:("00"+o.getUTCMilliseconds()).slice(-3)};for(var a in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(o.getUTCFullYear()+"").substr(4-RegExp.$1.length))),i)new RegExp("("+a+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?i[a]:("00"+i[a]).substr((""+i[a]).length)));return t}random(e,t){const r=(t||"ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789!@#$%^&*()_+-=").split("");let n="";for(let t=0;t<e;t++){n+=r[Math.floor(Math.random()*r.length)]}return n}toCamelCase(e,t,r){t=t||"-";let n=(e=e.toLowerCase()).split(t);e="";for(let t in n){let r=n[t];e+=r.replace(r[0],r[0].toUpperCase())}return r&&(e=e.replace(e[0],e[0].toLowerCase())),e}fromCamelCase(e,t){t=t||"-";const r=[];for(let t=0;t<e.length;t++){const o=e.charAt(t),i=o.toLowerCase();0===r.length?r.push(i):((n=o)>="A"&&n<="Z"&&r.push(""),r[r.length-1]=r[r.length-1]+=i)}var n;return r.join(t)}trigger(e){const t=this.uuid(),r=this.triggerQueue;return async()=>{if(r[t]||(r[t]={running:!1,again:!1}),r[t].running)r[t].again=!0;else{r[t].running=!0;const n=async()=>{await e(),r[t].again?(r[t].again=!1,await n()):delete r[t]};await n()}}}}},function(e,t){e.exports=require("crypto")},function(e,t){e.exports=require("uuid")},function(e,t){e.exports=require("qrcode")}]),global.dynamicRequire=require;var sumor_output=global.sumor_output;delete global.sumor_output,module.exports=sumor_output; |
{ | ||
"name": "@sumor/utils", | ||
"version": "11.0.0", | ||
"version": "11.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -44,4 +44,4 @@ 轻呈云工具集提供了Node.JS的基础常见工具,方便构建应用。 | ||
### getTimestamp | ||
获取UTC时间戳 | ||
获取时间戳 | ||
时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数。 | ||
```js | ||
@@ -62,4 +62,4 @@ const timestamp = utils.basic.getTimestamp(); | ||
### formatTime | ||
格式化日期时间,支持不同时区,支持数字格式时间戳和JS Date对象 | ||
格式化日期时间,支持不同时区,支持数字格式时间戳和JS Date对象,时区目前仅支持分钟差,不传则使用服务器时区。 | ||
utils.basic.formatTime(时间戳,格式[,时区]) | ||
```js | ||
@@ -66,0 +66,0 @@ const timeForUTC0 = utils.basic.formatTime(timestamp,'yyyy年MM月dd日 hh:mm:ss 星期W'); |
11061