fish-helper 0.0.53 → 0.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -20
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/types/index.d.ts +25 -0
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -6,23 +6,24 @@ npm install fish-helper
|
|
|
6
6
|
const helper = require("fish-helper");
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
| Method
|
|
10
|
-
|
|
|
11
|
-
| `add(hour, start)`
|
|
12
|
-
| `offset_time(date, type)`
|
|
13
|
-
| `before_lt_hour(date, hour)`
|
|
14
|
-
| `before_gt_hour(date, hour)`
|
|
15
|
-
| `after_lt_hour(date, hour)`
|
|
16
|
-
| `after_gt_hour(date, hour)`
|
|
17
|
-
| `is_current_year(date)`
|
|
18
|
-
| `get_time_obj(date)`
|
|
19
|
-
| `format_count({num, divide, suffix, show_suffix_always})`
|
|
20
|
-
| `format_num2date(timestamp)`
|
|
21
|
-
| `count_down(date, fn)`
|
|
22
|
-
| `count_down_by_remain_seconds(fn, seconds)`
|
|
23
|
-
| `format_thousandth(num)`
|
|
24
|
-
| `is_empty(data)`
|
|
25
|
-
| `poll(fn, minute)`
|
|
26
|
-
| `is_equal(a, b, exact)`
|
|
27
|
-
| contains(largeRangeData, smallRangeData, exact)
|
|
28
|
-
| `sleep(ms)`
|
|
9
|
+
| Method | Description |
|
|
10
|
+
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `add(hour, start)` | Add hour from start date, return timestamp. |
|
|
12
|
+
| `offset_time(date, type)` | The time difference (absolute value), returns the corresponding string. |
|
|
13
|
+
| `before_lt_hour(date, hour)` | The date is less than now, and the date is less than hour from now. |
|
|
14
|
+
| `before_gt_hour(date, hour)` | The date is less than now, and the date is greater than hour from now. |
|
|
15
|
+
| `after_lt_hour(date, hour)` | The date is greater than now, and the date is less than hour from now. |
|
|
16
|
+
| `after_gt_hour(date, hour)` | The date is greater than now, and the date is greater than hour from now. |
|
|
17
|
+
| `is_current_year(date)` | Return boolean. |
|
|
18
|
+
| `get_time_obj(date)` | Return object that includes keys: year, month, day, hour, minute, seconds, day_of_week. |
|
|
19
|
+
| `format_count({num, divide, suffix, show_suffix_always})` | Return num or string or 0. |
|
|
20
|
+
| `format_num2date(timestamp)` | Convert time to object; return object that includes keys: day, hour, minute, seconds. |
|
|
21
|
+
| `count_down(date, fn)` | End time countdown, end time can be passed in by itself; fn is a callback function that takes a remaining time argument; return a function to stop the timer. |
|
|
22
|
+
| `count_down_by_remain_seconds(fn, seconds)` | 60-second countdown. Time can pass by itself. |
|
|
23
|
+
| `format_thousandth(num)` | Format the data as a string with thousands of bits. |
|
|
24
|
+
| `is_empty(data)` | Determines whether the data is empty. |
|
|
25
|
+
| `poll(fn, minute)` | Execute fn function every minute, return function to stop the fn. |
|
|
26
|
+
| `is_equal(a, b, exact)` | Return boolean, compare a and b; a and b are any type of data. |
|
|
27
|
+
| contains(largeRangeData, smallRangeData, exact) | Return boolean. |
|
|
28
|
+
| `sleep(ms)` | Suspend |
|
|
29
|
+
| `check_pattern({likeStr, str, separator, symbol, caseSensitive})` | Return boolean. Check if str matches likeStr pattern. |
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";function t(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)}function e(t,e,r,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(t,r):s?s.value=r:e.set(t,r),r}var r,i,s,l,n,a,o,h,u,c,f,d,m;Object.defineProperty(exports,"__esModule",{value:!0}),"function"==typeof SuppressedError&&SuppressedError;const _=()=>null;r=new WeakMap,i=new WeakMap,s=new WeakMap,l=new WeakMap,n=new WeakMap,a=new WeakMap,o=new WeakMap,h=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,d=new WeakMap,m=new WeakMap;const p=new class{constructor(){r.set(this,1e3),i.set(this,36e5),s.set(this,null),l.set(this,null),n.set(this,t=>Object.prototype.toString.call(t).slice(8,-1)),a.set(this,t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let r=new Date(e);return"Invalid Date"===r.toString()&&(r=new Date(t)),r.getTime()}),o.set(this,e=>"Function"===t(this,n,"f").call(this,e)),h.set(this,e=>"Array"===t(this,n,"f").call(this,e)),u.set(this,e=>"Object"===t(this,n,"f").call(this,e)),c.set(this,t=>String(t).padStart(2,"0")),f.set(this,({date:e,hour:r=1,type:s="before_lt_hour"})=>{let l=t(this,a,"f").call(this,e);const n=new Date(l).getTime(),o=Date.now(),h=n<o,u=n>o;return"before_lt_hour"===s?h&&n+t(this,i,"f")*r>o:"before_gt_hour"===s?h&&n+t(this,i,"f")*r<o:"after_lt_hour"===s?u&&o+t(this,i,"f")*r>n:"after_gt_hour"===s&&(u&&o+t(this,i,"f")*r<n)}),this.offset_time=(e,r="minute")=>{const i=Math.abs(Date.now()-t(this,a,"f").call(this,e)),s=this.format_num2date(i);return"day"===r?t(this,c,"f").call(this,s.day):"hour"===r?t(this,c,"f").call(this,s.hour):"minute"===r?t(this,c,"f").call(this,s.minute):"second"===r?t(this,c,"f").call(this,s.seconds):"The second parameter has an error"},d.set(this,(i=0,s=_,n=t(this,r,"f"),a=0,o=Date.now())=>{if(i<=0)return clearTimeout(t(this,l,"f")),void e(this,l,null,"f");clearTimeout(t(this,l,"f")),e(this,l,setTimeout(()=>{a+=1,i-=t(this,r,"f");let e=this.format_timestamp_to_day_hour_minute_second(i);s({remain:i,obj:e});const l=Date.now()-(o+a*t(this,r,"f"));let n=t(this,r,"f")-l;n<0&&(n=0),t(this,d,"f").call(this,i,s,n,a,o)},n),"f")}),m.set(this,(i=0,l=_,n=t(this,r,"f"),a=0,o=Date.now())=>{if(i<=0)return clearTimeout(t(this,s,"f")),void e(this,s,null,"f");clearTimeout(t(this,s,"f")),e(this,s,setTimeout(()=>{a+=1,i-=t(this,r,"f");let e=this.format_num2date(i);l({remain:i,obj:e});const s=Date.now()-(o+a*t(this,r,"f"));let n=t(this,r,"f")-s;n<0&&(n=0),t(this,m,"f").call(this,i,l,n,a,o)},n),"f")}),this.sleep=t=>new Promise(e=>setTimeout(e,t)),this.roxFormatThousandth=(t,e="万")=>t<1e4?t:(Math.floor(t/1e3)/10).toFixed(1)+e,this.chunk=(t,e,r=!1)=>{if(!Array.isArray(t)||e<=0)return[];const i=[];for(let s=0;s<t.length;s+=e){const l=t.slice(s,s+e);r?l.length===e&&i.push(l):i.push(l)}return i},this.debounce=(t,e=200,r=!1)=>{let i,s=null;return function(...l){const n=this,a=r&&!s;return s&&clearTimeout(s),s=setTimeout(()=>{s=null,r||(i=t.apply(n,l))},e),a&&(i=t.apply(n,l)),i}},this.flatten=(t,e=!1)=>{let r=[];return t.forEach(t=>{e&&Array.isArray(t)?r=r.concat(this.flatten(t,e)):r.push(t)}),r},this.safeRequest=(t,e)=>t&&t.then?t.catch?t.then(t=>[null,t]).catch(t=>(e&&Object.assign(t,e),[t,void 0])):t.then(t=>[null,t]):Promise.resolve([null,t]),this.checkPattern=t=>{const{str:e,likeStr:r,separator:i="-",caseSensitive:s=!1,symbol:l=""}=t,n=(r||"").split(i),a=(e||"").split(i);return n.every((t,e)=>t===l||(s?t===a[e]:a[e]&&t.toLowerCase()===a[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:s,checkedIndexArr:l=[],combineSkuArr:n=[],disabledArr:a=[],combineSeparator:o="-",combineSkuField:h="id"}=t;for(let t=0;t<i.length;t++){const u=s?(null===(e=i[t])||void 0===e?void 0:e[s])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<u.length;e++){const i=l.slice(0,t),s=l.slice(t+1),u=i.concat(e).concat(s).join(o),c=n.filter(t=>this.checkPattern({str:t[h],likeStr:u,separator:o}));for(let i of a){const{field:s,disabledFun:l,disabledFieldValue:n}=i,a=c.length;t:for(let i=0;i<c.length;i++){if(l(c[i])){r[t][e]={[s]:n};break t}i===a-1&&(r[t][e]={[s]:!n})}}}}return r}}before_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,a,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,a,"f").call(this,e),i=new Date(r),s=t(this,c,"f").call(this,i.getMonth()+1),l=t(this,c,"f").call(this,i.getDate()),n=t(this,c,"f").call(this,i.getHours()),o=t(this,c,"f").call(this,i.getMinutes()),h=t(this,c,"f").call(this,i.getSeconds());return{year:String(i.getFullYear()),month:s,day:l,hour:n,minute:o,seconds:h,day_of_week:String(i.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:s=!1}){if(!t)return 0;if(r<=0||e<0)return s?`${t} ${i}`:t;const l=parseFloat(t);if(l<=0)return s?`${l} ${i}`:l;if(l>0&&l<r)return s?`${l} ${i}`:l;const[n,a]=(l/r).toFixed(e).split(".");return a&&0!==parseFloat(a)?`${n}.${a} ${i}`:`${n} ${i}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),i=parseInt(e/1e3/60/60%24),s=parseInt(e/1e3/60%60),l=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,s),seconds:t(this,c,"f").call(this,l)}}count_down_by_remain_seconds(t=_,e=60){let r;clearTimeout(r);let i=1e3*e,s=this.format_num2date(i),l={remain:i,obj:s};t(l);let n=this;return function t(e=0,a=_,o=1e3,h=0,u=Date.now()){if(e<=0)return clearTimeout(r),n=null,r=null,i=null,s=null,l=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(r),r=setTimeout(()=>{h+=1,e-=1e3;let r=n.format_num2date(e);a({remain:e,obj:r});let i=1e3-(Date.now()-(u+1e3*h));i<0&&(i=0),t(e,a,i,h,u)},o)}(i,t,1e3),()=>{clearTimeout(r),n=null,r=null,i=null,s=null,l=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const r=Math.floor(e/864e5),i=Math.floor(e%864e5/36e5),s=Math.floor(e%36e5/6e4),l=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,s),seconds:t(this,c,"f").call(this,l)}}count_down(e=Date.now(),r=_){let i;clearTimeout(i);let s=this,l=t(this,a,"f").call(this,e),n=l-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(n),h={remain:n,obj:o};return r(h),function t(e=0,r=_,a=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(i),i=null,s=null,l=null,n=null,o=null,h=null,void r({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{u+=1,e-=1e3;let i=s.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:i});let l=1e3-(Date.now()-(c+1e3*u));l<0&&(l=0),t(e,r,l,u,c)},a)}(n,r,1e3),()=>{clearTimeout(i),i=null,s=null,l=null,n=null,o=null,h=null}}add(e=1,r=Date.now()){return t(this,a,"f").call(this,r)+60*e*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let s=!1,l="";i[1]&&(l=i[1].replace(/0+$/,""),s=l.length>0);let n=0;s&&(n=void 0!==e?e:l.length);const a=r.toFixed(n).split("."),o=(a[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return a[1]?`${o}.${a[1]}`:o}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const r=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let i=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return r&&(i=i.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),i}catch(t){return 0}}is_empty(e){return null==e||("String"===t(this,n,"f").call(this,e)?!e.trim():"Array"===t(this,n,"f").call(this,e)?!e.length:"Object"===t(this,n,"f").call(this,e)&&!Object.keys(e).length)}poll(e,r=1){let i;if(!t(this,o,"f").call(this,e))return()=>{clearTimeout(i),i=void 0};const s=60*r*1e3,l=()=>{e(),i=setTimeout(l,s)};return l(),()=>{clearTimeout(i),i=void 0}}is_equal(e,r,i=!1){const s=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),l=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!s||!l)return i?e===r:e==r;const n=Object.keys(e),a=Object.keys(r);return 0===n.length&&0===a.length||n.length===a.length&&n.every(s=>{const l=t(this,h,"f").call(this,e[s])||t(this,u,"f").call(this,e[s]),n=t(this,h,"f").call(this,r[s])||t(this,u,"f").call(this,r[s]);return l&&n?this.is_equal(e[s],r[s],i):i?e[s]===r[s]:e[s]==r[s]})}contains(e,r,i=!1){const s=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),l=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!s||!l)return i?e===r:e==r;const n=Object.keys(e),a=Object.keys(r);return 0===a.length||!(0===n.length||n.length<a.length)&&a.every(s=>{if(n.indexOf(s)<0)return!1;const l=t(this,h,"f").call(this,e[s])||t(this,u,"f").call(this,e[s]),a=t(this,h,"f").call(this,r[s])||t(this,u,"f").call(this,r[s]);return l&&a?this.contains(e[s],r[s],i):i?e[s]===r[s]:e[s]==r[s]})}};exports.default=p,exports.helper=p;
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function t(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)}function e(t,e,r,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(t,r):s?s.value=r:e.set(t,r),r}var r,i,s,l,n,a,o,h,u,c,f,d,m;"function"==typeof SuppressedError&&SuppressedError;const _=()=>null;r=new WeakMap,i=new WeakMap,s=new WeakMap,l=new WeakMap,n=new WeakMap,a=new WeakMap,o=new WeakMap,h=new WeakMap,u=new WeakMap,c=new WeakMap,f=new WeakMap,d=new WeakMap,m=new WeakMap;const p=new class{constructor(){r.set(this,1e3),i.set(this,36e5),s.set(this,null),l.set(this,null),n.set(this,t=>Object.prototype.toString.call(t).slice(8,-1)),a.set(this,t=>{if(!t)return Date.now();let e=null;e="string"==typeof t?t.replace(/(\-|\_)/g,"/"):new Date(t);let r=new Date(e);return"Invalid Date"===r.toString()&&(r=new Date(t)),r.getTime()}),o.set(this,e=>"Function"===t(this,n,"f").call(this,e)),h.set(this,e=>"Array"===t(this,n,"f").call(this,e)),u.set(this,e=>"Object"===t(this,n,"f").call(this,e)),c.set(this,t=>String(t).padStart(2,"0")),f.set(this,({date:e,hour:r=1,type:s="before_lt_hour"})=>{let l=t(this,a,"f").call(this,e);const n=new Date(l).getTime(),o=Date.now(),h=n<o,u=n>o;return"before_lt_hour"===s?h&&n+t(this,i,"f")*r>o:"before_gt_hour"===s?h&&n+t(this,i,"f")*r<o:"after_lt_hour"===s?u&&o+t(this,i,"f")*r>n:"after_gt_hour"===s&&(u&&o+t(this,i,"f")*r<n)}),this.offset_time=(e,r="minute")=>{const i=Math.abs(Date.now()-t(this,a,"f").call(this,e)),s=this.format_num2date(i);return"day"===r?t(this,c,"f").call(this,s.day):"hour"===r?t(this,c,"f").call(this,s.hour):"minute"===r?t(this,c,"f").call(this,s.minute):"second"===r?t(this,c,"f").call(this,s.seconds):"The second parameter has an error"},d.set(this,(i=0,s=_,n=t(this,r,"f"),a=0,o=Date.now())=>{if(i<=0)return clearTimeout(t(this,l,"f")),void e(this,l,null,"f");clearTimeout(t(this,l,"f")),e(this,l,setTimeout(()=>{a+=1,i-=t(this,r,"f");let e=this.format_timestamp_to_day_hour_minute_second(i);s({remain:i,obj:e});const l=Date.now()-(o+a*t(this,r,"f"));let n=t(this,r,"f")-l;n<0&&(n=0),t(this,d,"f").call(this,i,s,n,a,o)},n),"f")}),m.set(this,(i=0,l=_,n=t(this,r,"f"),a=0,o=Date.now())=>{if(i<=0)return clearTimeout(t(this,s,"f")),void e(this,s,null,"f");clearTimeout(t(this,s,"f")),e(this,s,setTimeout(()=>{a+=1,i-=t(this,r,"f");let e=this.format_num2date(i);l({remain:i,obj:e});const s=Date.now()-(o+a*t(this,r,"f"));let n=t(this,r,"f")-s;n<0&&(n=0),t(this,m,"f").call(this,i,l,n,a,o)},n),"f")}),this.sleep=t=>new Promise(e=>setTimeout(e,t)),this.roxFormatThousandth=(t,e="万")=>t<1e4?t:(Math.floor(t/1e3)/10).toFixed(1)+e,this.chunk=(t,e,r=!1)=>{if(!Array.isArray(t)||e<=0)return[];const i=[];for(let s=0;s<t.length;s+=e){const l=t.slice(s,s+e);r?l.length===e&&i.push(l):i.push(l)}return i},this.debounce=(t,e=200,r=!1)=>{let i,s=null;return function(...l){const n=this,a=r&&!s;return s&&clearTimeout(s),s=setTimeout(()=>{s=null,r||(i=t.apply(n,l))},e),a&&(i=t.apply(n,l)),i}},this.flatten=(t,e=!1)=>{let r=[];return t.forEach(t=>{e&&Array.isArray(t)?r=r.concat(this.flatten(t,e)):r.push(t)}),r},this.safeRequest=(t,e)=>t&&t.then?t.catch?t.then(t=>[null,t]).catch(t=>(e&&Object.assign(t,e),[t,void 0])):t.then(t=>[null,t]):Promise.resolve([null,t]),this.checkPattern=t=>{const{str:e,likeStr:r,separator:i="-",caseSensitive:s=!1,symbol:l=""}=t,n=(r||"").split(i),a=(e||"").split(i);return n.every((t,e)=>t===l||(s?t===a[e]:a[e]&&t.toLowerCase()===a[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:s,checkedIndexArr:l=[],combineSkuArr:n=[],disabledArr:a=[],combineSeparator:o="-",combineSkuField:h="id"}=t;for(let t=0;t<i.length;t++){const u=s?(null===(e=i[t])||void 0===e?void 0:e[s])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<u.length;e++){const i=l.slice(0,t),s=l.slice(t+1),u=i.concat(e).concat(s).join(o),c=n.filter(t=>this.checkPattern({str:t[h],likeStr:u,separator:o}));for(let i of a){const{field:s,disabledFun:l,disabledFieldValue:n}=i,a=c.length;t:for(let i=0;i<c.length;i++){if(l(c[i])){r[t][e]={[s]:n};break t}i===a-1&&(r[t][e]={[s]:!n})}}}}return r}}before_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_lt_hour"})}before_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"before_gt_hour"})}after_lt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_lt_hour"})}after_gt_hour(e=Date.now(),r=1){return t(this,f,"f").call(this,{date:e,hour:r,type:"after_gt_hour"})}is_current_year(e){const r=t(this,a,"f").call(this,e);return(new Date).getFullYear()===new Date(r).getFullYear()}get_time_obj(e){const r=t(this,a,"f").call(this,e),i=new Date(r),s=t(this,c,"f").call(this,i.getMonth()+1),l=t(this,c,"f").call(this,i.getDate()),n=t(this,c,"f").call(this,i.getHours()),o=t(this,c,"f").call(this,i.getMinutes()),h=t(this,c,"f").call(this,i.getSeconds());return{year:String(i.getFullYear()),month:s,day:l,hour:n,minute:o,seconds:h,day_of_week:String(i.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:s=!1}){if(!t)return 0;if(r<=0||e<0)return s?`${t} ${i}`:t;const l=parseFloat(t);if(l<=0)return s?`${l} ${i}`:l;if(l>0&&l<r)return s?`${l} ${i}`:l;const[n,a]=(l/r).toFixed(e).split(".");return a&&0!==parseFloat(a)?`${n}.${a} ${i}`:`${n} ${i}`}format_num2date(e=Date.now()){const r=parseInt(e/1e3/60/60/24%24),i=parseInt(e/1e3/60/60%24),s=parseInt(e/1e3/60%60),l=parseInt(e/1e3%60);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,s),seconds:t(this,c,"f").call(this,l)}}count_down_by_remain_seconds(t=_,e=60){let r;clearTimeout(r);let i=1e3*e,s=this.format_num2date(i),l={remain:i,obj:s};t(l);let n=this;return function t(e=0,a=_,o=1e3,h=0,u=Date.now()){if(e<=0)return clearTimeout(r),n=null,r=null,i=null,s=null,l=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(r),r=setTimeout(()=>{h+=1,e-=1e3;let r=n.format_num2date(e);a({remain:e,obj:r});let i=1e3-(Date.now()-(u+1e3*h));i<0&&(i=0),t(e,a,i,h,u)},o)}(i,t,1e3),()=>{clearTimeout(r),n=null,r=null,i=null,s=null,l=null}}format_timestamp_to_day_hour_minute_second(e=Date.now()){const r=Math.floor(e/864e5),i=Math.floor(e%864e5/36e5),s=Math.floor(e%36e5/6e4),l=Math.floor(e%6e4/1e3);return{day:t(this,c,"f").call(this,r),hour:t(this,c,"f").call(this,i),minute:t(this,c,"f").call(this,s),seconds:t(this,c,"f").call(this,l)}}count_down(e=Date.now(),r=_){let i;clearTimeout(i);let s=this,l=t(this,a,"f").call(this,e),n=l-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(n),h={remain:n,obj:o};return r(h),function t(e=0,r=_,a=1e3,u=0,c=Date.now()){if(e<=0)return clearTimeout(i),i=null,s=null,l=null,n=null,o=null,h=null,void r({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{u+=1,e-=1e3;let i=s.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:i});let l=1e3-(Date.now()-(c+1e3*u));l<0&&(l=0),t(e,r,l,u,c)},a)}(n,r,1e3),()=>{clearTimeout(i),i=null,s=null,l=null,n=null,o=null,h=null}}add(e=1,r=Date.now()){return t(this,a,"f").call(this,r)+60*e*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let s=!1,l="";i[1]&&(l=i[1].replace(/0+$/,""),s=l.length>0);let n=0;s&&(n=void 0!==e?e:l.length);const a=r.toFixed(n).split("."),o=(a[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return a[1]?`${o}.${a[1]}`:o}catch(t){return 0}}format_thousandth_with_same_dotlen(t){var e;try{const r=(null===(e=t.toString().split(".")[1])||void 0===e?void 0:e.length)||0;let i=t.toString().replace(/\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+$)/g,function(t){return t+","})});return r&&(i=i.replace(/\d+\.\d+/,function(t){return t.replace(/(\d)(?=(\d{3})+\.)/g,function(t){return t+","})})),i}catch(t){return 0}}is_empty(e){return null==e||("String"===t(this,n,"f").call(this,e)?!e.trim():"Array"===t(this,n,"f").call(this,e)?!e.length:"Object"===t(this,n,"f").call(this,e)&&!Object.keys(e).length)}poll(e,r=1){let i;if(!t(this,o,"f").call(this,e))return()=>{clearTimeout(i),i=void 0};const s=60*r*1e3,l=()=>{e(),i=setTimeout(l,s)};return l(),()=>{clearTimeout(i),i=void 0}}is_equal(e,r,i=!1){const s=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),l=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!s||!l)return i?e===r:e==r;const n=Object.keys(e),a=Object.keys(r);return 0===n.length&&0===a.length||n.length===a.length&&n.every(s=>{const l=t(this,h,"f").call(this,e[s])||t(this,u,"f").call(this,e[s]),n=t(this,h,"f").call(this,r[s])||t(this,u,"f").call(this,r[s]);return l&&n?this.is_equal(e[s],r[s],i):i?e[s]===r[s]:e[s]==r[s]})}contains(e,r,i=!1){const s=t(this,h,"f").call(this,e)||t(this,u,"f").call(this,e),l=t(this,h,"f").call(this,r)||t(this,u,"f").call(this,r);if(!s||!l)return i?e===r:e==r;const n=Object.keys(e),a=Object.keys(r);return 0===a.length||!(0===n.length||n.length<a.length)&&a.every(s=>{if(n.indexOf(s)<0)return!1;const l=t(this,h,"f").call(this,e[s])||t(this,u,"f").call(this,e[s]),a=t(this,h,"f").call(this,r[s])||t(this,u,"f").call(this,r[s]);return l&&a?this.contains(e[s],r[s],i):i?e[s]===r[s]:e[s]==r[s]})}};export{p as default,p as helper};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -21,6 +21,27 @@ interface CountDownCallbackParams {
|
|
|
21
21
|
remain: number;
|
|
22
22
|
obj: FormatNum2Date;
|
|
23
23
|
}
|
|
24
|
+
interface CheckPatternArgs {
|
|
25
|
+
str: string;
|
|
26
|
+
likeStr: string;
|
|
27
|
+
separator?: string;
|
|
28
|
+
caseSensitive?: boolean;
|
|
29
|
+
symbol?: string;
|
|
30
|
+
}
|
|
31
|
+
interface DisabledFunObj<T> {
|
|
32
|
+
field: string;
|
|
33
|
+
disabledFun: (item: T) => boolean;
|
|
34
|
+
disabledFieldValue: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface TransformDisableArgs<T = any> {
|
|
37
|
+
skuObjArr: any[];
|
|
38
|
+
skuArrField?: string;
|
|
39
|
+
checkedIndexArr: (number | undefined)[];
|
|
40
|
+
combineSkuArr: T[];
|
|
41
|
+
combineSkuField: string;
|
|
42
|
+
combineSeparator?: string;
|
|
43
|
+
disabledArr?: Array<DisabledFunObj<T>>;
|
|
44
|
+
}
|
|
24
45
|
type CountDownCallback = (data: CountDownCallbackParams) => any;
|
|
25
46
|
declare class Helper {
|
|
26
47
|
#private;
|
|
@@ -56,6 +77,10 @@ declare class Helper {
|
|
|
56
77
|
debounce: (func: (...args: any[]) => any, wait?: number, immediate?: boolean) => (this: any, ...args: any[]) => any;
|
|
57
78
|
flatten: <T>(arr: T[], deep?: boolean) => T[];
|
|
58
79
|
safeRequest: <T = any>(promise: Promise<any>, errorInfo?: Record<string, any>) => Promise<[Error | null, T | undefined]>;
|
|
80
|
+
checkPattern: (arg: CheckPatternArgs) => boolean;
|
|
81
|
+
convertArr2Disable: <T>(arg: TransformDisableArgs<T>) => {
|
|
82
|
+
[key: string]: boolean;
|
|
83
|
+
}[][];
|
|
59
84
|
}
|
|
60
85
|
declare const helper: Helper;
|
|
61
86
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fish-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.55",
|
|
4
4
|
"description": "a tool to process time",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/es/index.js",
|
|
@@ -23,18 +23,13 @@
|
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"tslib": "^2.8.1"
|
|
28
|
-
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"tslib": "^2.8.1"
|
|
31
|
-
},
|
|
32
26
|
"buildOptions": {
|
|
33
27
|
"name": "helper",
|
|
34
28
|
"formats": [
|
|
35
29
|
"cjs",
|
|
36
30
|
"es"
|
|
37
|
-
]
|
|
31
|
+
],
|
|
32
|
+
"external": []
|
|
38
33
|
},
|
|
39
34
|
"scripts": {}
|
|
40
35
|
}
|