fish-helper 0.0.61 → 0.0.62
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 +2 -0
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/types/index.d.ts +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,3 +27,5 @@ const helper = require("fish-helper");
|
|
|
27
27
|
| contains(largeRangeData, smallRangeData, exact) | Return boolean. |
|
|
28
28
|
| `sleep(ms)` | Suspend |
|
|
29
29
|
| `checkPattern({likeStr, str, separator, symbol, caseSensitive})` | Return boolean. Check if str matches likeStr pattern. |
|
|
30
|
+
| `createSingleton(fn)` | Return function. Create a singleton function. |
|
|
31
|
+
| `findDeepValue(options)` | Return object. Find the deep value in the list. |
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=()=>null;const e=new class{constructor(){this.__interval=1e3,this.__an_hour=36e5,this.__ticker=null,this.__ticker2=null,this.__get_type=t=>Object.prototype.toString.call(t).slice(8,-1),this.__date2timestamp=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()},this.__is_function=t=>"Function"===this.__get_type(t),this.__is_array=t=>"Array"===this.__get_type(t),this.__is_object=t=>"Object"===this.__get_type(t),this.__get_suffix2=t=>String(t).padStart(2,"0"),this.__compare_time=({date:t,hour:e=1,type:r="before_lt_hour"})=>{let i=this.__date2timestamp(t);const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=()=>null;const e=new class{constructor(){this.__interval=1e3,this.__an_hour=36e5,this.__ticker=null,this.__ticker2=null,this.__get_type=t=>Object.prototype.toString.call(t).slice(8,-1),this.__date2timestamp=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()},this.__is_function=t=>"Function"===this.__get_type(t),this.__is_array=t=>"Array"===this.__get_type(t),this.__is_object=t=>"Object"===this.__get_type(t),this.__get_suffix2=t=>String(t).padStart(2,"0"),this.__compare_time=({date:t,hour:e=1,type:r="before_lt_hour"})=>{let i=this.__date2timestamp(t);const n=new Date(i).getTime(),s=Date.now(),_=n<s,o=n>s;return"before_lt_hour"===r?_&&n+this.__an_hour*e>s:"before_gt_hour"===r?_&&n+this.__an_hour*e<s:"after_lt_hour"===r?o&&s+this.__an_hour*e>n:"after_gt_hour"===r&&(o&&s+this.__an_hour*e<n)},this.offset_time=(t,e="minute")=>{const r=Math.abs(Date.now()-this.__date2timestamp(t)),i=this.format_num2date(r);return"day"===e?this.__get_suffix2(i.day):"hour"===e?this.__get_suffix2(i.hour):"minute"===e?this.__get_suffix2(i.minute):"second"===e?this.__get_suffix2(i.seconds):"The second parameter has an error"},this.__loop_time2=(e=0,r=t,i=this.__interval,n=0,s=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker2),void(this.__ticker2=null);clearTimeout(this.__ticker2),this.__ticker2=setTimeout(()=>{n+=1,e-=this.__interval;let t=this.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:t});const i=Date.now()-(s+n*this.__interval);let _=this.__interval-i;_<0&&(_=0),this.__loop_time2(e,r,_,n,s)},i)},this.__loop_time=(e=0,r=t,i=this.__interval,n=0,s=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker),void(this.__ticker=null);clearTimeout(this.__ticker),this.__ticker=setTimeout(()=>{n+=1,e-=this.__interval;let t=this.format_num2date(e);r({remain:e,obj:t});const i=Date.now()-(s+n*this.__interval);let _=this.__interval-i;_<0&&(_=0),this.__loop_time(e,r,_,n,s)},i)},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 n=0;n<t.length;n+=e){const s=t.slice(n,n+e);r?s.length===e&&i.push(s):i.push(s)}return i},this.debounce=(t,e=200,r=!1)=>{let i,n=null;return function(...s){const _=this,o=r&&!n;return n&&clearTimeout(n),n=setTimeout(()=>{n=null,r||(i=t.apply(_,s))},e),o&&(i=t.apply(_,s)),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:n=!1,symbol:s=""}=t,_=(r||"").split(i),o=(e||"").split(i);return _.every((t,e)=>t===s||(n?t===o[e]:o[e]&&t.toLowerCase()===o[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:n,checkedIndexArr:s=[],combineSkuArr:_=[],disabledArr:o=[],combineSeparator:a="-",combineSkuField:u="id"}=t;for(let t=0;t<i.length;t++){const l=n?(null===(e=i[t])||void 0===e?void 0:e[n])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<l.length;e++){const i=s.slice(0,t),n=s.slice(t+1),l=i.concat(e).concat(n).join(a),h=_.filter(t=>this.checkPattern({str:t[u],likeStr:l,separator:a})),c=o.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,n=h.some(t=>r(t));return{[e]:n?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=c}}return r},this.createSingleTon=t=>{let e=null;const r=new Proxy(t,{construct:(t,r)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,r):new t(...r),e)});return r.prototype.constructor=r,r},this.findDeepValue=t=>{const{list:e,selected:r,selectedValueInListFieldName:i,childrenFieldName:n}=t;if(!r.length)return;const s=r[r.length-1],_=t=>{for(const e of t){if(e[i]===s)return e;const t=e[n];if(Array.isArray(t)&&t.length){const e=_(t);if(e)return e}}};return _(e)}}before_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_lt_hour"})}before_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_gt_hour"})}after_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_lt_hour"})}after_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_gt_hour"})}is_current_year(t){const e=this.__date2timestamp(t);return(new Date).getFullYear()===new Date(e).getFullYear()}get_time_obj(t){const e=this.__date2timestamp(t),r=new Date(e),i=this.__get_suffix2(r.getMonth()+1),n=this.__get_suffix2(r.getDate()),s=this.__get_suffix2(r.getHours()),_=this.__get_suffix2(r.getMinutes()),o=this.__get_suffix2(r.getSeconds());return{year:String(r.getFullYear()),month:i,day:n,hour:s,minute:_,seconds:o,day_of_week:String(r.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:n=!1}){if(!t)return 0;if(r<=0||e<0)return n?`${t} ${i}`:t;const s=parseFloat(t);if(s<=0)return n?`${s} ${i}`:s;if(s>0&&s<r)return n?`${s} ${i}`:s;const[_,o]=(s/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${_}.${o} ${i}`:`${_} ${i}`}format_num2date(t=Date.now()){const e=parseInt(t/1e3/60/60/24%24),r=parseInt(t/1e3/60/60%24),i=parseInt(t/1e3/60%60),n=parseInt(t/1e3%60);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down_by_remain_seconds(e=t,r=60){let i;clearTimeout(i);let n=1e3*r,s=this.format_num2date(n),_={remain:n,obj:s};e(_);let o=this;return function e(r=0,a=t,u=1e3,l=0,h=Date.now()){if(r<=0)return clearTimeout(i),o=null,i=null,n=null,s=null,_=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{l+=1,r-=1e3;let t=o.format_num2date(r);a({remain:r,obj:t});let i=1e3-(Date.now()-(h+1e3*l));i<0&&(i=0),e(r,a,i,l,h)},u)}(n,e,1e3),()=>{clearTimeout(i),o=null,i=null,n=null,s=null,_=null}}format_timestamp_to_day_hour_minute_second(t=Date.now()){const e=Math.floor(t/864e5),r=Math.floor(t%864e5/36e5),i=Math.floor(t%36e5/6e4),n=Math.floor(t%6e4/1e3);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down(e=Date.now(),r=t){let i;clearTimeout(i);let n=this,s=this.__date2timestamp(e),_=s-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(_),a={remain:_,obj:o};return r(a),function e(r=0,u=t,l=1e3,h=0,c=Date.now()){if(r<=0)return clearTimeout(i),i=null,n=null,s=null,_=null,o=null,a=null,void u({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{h+=1,r-=1e3;let t=n.format_timestamp_to_day_hour_minute_second(r);u({remain:r,obj:t});let i=1e3-(Date.now()-(c+1e3*h));i<0&&(i=0),e(r,u,i,h,c)},l)}(_,r,1e3),()=>{clearTimeout(i),i=null,n=null,s=null,_=null,o=null,a=null}}add(t=1,e=Date.now()){return this.__date2timestamp(e)+60*t*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let n=!1,s="";i[1]&&(s=i[1].replace(/0+$/,""),n=s.length>0);let _=0;n&&(_=void 0!==e?e:s.length);const o=r.toFixed(_).split("."),a=(o[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return o[1]?`${a}.${o[1]}`:a}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(t){return null==t||("String"===this.__get_type(t)?!t.trim():"Array"===this.__get_type(t)?!t.length:"Object"===this.__get_type(t)&&!Object.keys(t).length)}poll(t,e=1){let r;if(!this.__is_function(t))return()=>{clearTimeout(r),r=void 0};const i=60*e*1e3,n=()=>{t(),r=setTimeout(n,i)};return n(),()=>{clearTimeout(r),r=void 0}}is_equal(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const s=Object.keys(t),_=Object.keys(e);return 0===s.length&&0===_.length||s.length===_.length&&s.every(i=>{const n=this.__is_array(t[i])||this.__is_object(t[i]),s=this.__is_array(e[i])||this.__is_object(e[i]);return n&&s?this.is_equal(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}contains(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const s=Object.keys(t),_=Object.keys(e);return 0===_.length||!(0===s.length||s.length<_.length)&&_.every(i=>{if(s.indexOf(i)<0)return!1;const n=this.__is_array(t[i])||this.__is_object(t[i]),_=this.__is_array(e[i])||this.__is_object(e[i]);return n&&_?this.contains(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}};exports.default=e,exports.helper=e;
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=()=>null;const e=new class{constructor(){this.__interval=1e3,this.__an_hour=36e5,this.__ticker=null,this.__ticker2=null,this.__get_type=t=>Object.prototype.toString.call(t).slice(8,-1),this.__date2timestamp=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()},this.__is_function=t=>"Function"===this.__get_type(t),this.__is_array=t=>"Array"===this.__get_type(t),this.__is_object=t=>"Object"===this.__get_type(t),this.__get_suffix2=t=>String(t).padStart(2,"0"),this.__compare_time=({date:t,hour:e=1,type:r="before_lt_hour"})=>{let i=this.__date2timestamp(t);const n=new Date(i).getTime(),
|
|
1
|
+
const t=()=>null;const e=new class{constructor(){this.__interval=1e3,this.__an_hour=36e5,this.__ticker=null,this.__ticker2=null,this.__get_type=t=>Object.prototype.toString.call(t).slice(8,-1),this.__date2timestamp=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()},this.__is_function=t=>"Function"===this.__get_type(t),this.__is_array=t=>"Array"===this.__get_type(t),this.__is_object=t=>"Object"===this.__get_type(t),this.__get_suffix2=t=>String(t).padStart(2,"0"),this.__compare_time=({date:t,hour:e=1,type:r="before_lt_hour"})=>{let i=this.__date2timestamp(t);const n=new Date(i).getTime(),s=Date.now(),_=n<s,o=n>s;return"before_lt_hour"===r?_&&n+this.__an_hour*e>s:"before_gt_hour"===r?_&&n+this.__an_hour*e<s:"after_lt_hour"===r?o&&s+this.__an_hour*e>n:"after_gt_hour"===r&&(o&&s+this.__an_hour*e<n)},this.offset_time=(t,e="minute")=>{const r=Math.abs(Date.now()-this.__date2timestamp(t)),i=this.format_num2date(r);return"day"===e?this.__get_suffix2(i.day):"hour"===e?this.__get_suffix2(i.hour):"minute"===e?this.__get_suffix2(i.minute):"second"===e?this.__get_suffix2(i.seconds):"The second parameter has an error"},this.__loop_time2=(e=0,r=t,i=this.__interval,n=0,s=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker2),void(this.__ticker2=null);clearTimeout(this.__ticker2),this.__ticker2=setTimeout(()=>{n+=1,e-=this.__interval;let t=this.format_timestamp_to_day_hour_minute_second(e);r({remain:e,obj:t});const i=Date.now()-(s+n*this.__interval);let _=this.__interval-i;_<0&&(_=0),this.__loop_time2(e,r,_,n,s)},i)},this.__loop_time=(e=0,r=t,i=this.__interval,n=0,s=Date.now())=>{if(e<=0)return clearTimeout(this.__ticker),void(this.__ticker=null);clearTimeout(this.__ticker),this.__ticker=setTimeout(()=>{n+=1,e-=this.__interval;let t=this.format_num2date(e);r({remain:e,obj:t});const i=Date.now()-(s+n*this.__interval);let _=this.__interval-i;_<0&&(_=0),this.__loop_time(e,r,_,n,s)},i)},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 n=0;n<t.length;n+=e){const s=t.slice(n,n+e);r?s.length===e&&i.push(s):i.push(s)}return i},this.debounce=(t,e=200,r=!1)=>{let i,n=null;return function(...s){const _=this,o=r&&!n;return n&&clearTimeout(n),n=setTimeout(()=>{n=null,r||(i=t.apply(_,s))},e),o&&(i=t.apply(_,s)),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:n=!1,symbol:s=""}=t,_=(r||"").split(i),o=(e||"").split(i);return _.every((t,e)=>t===s||(n?t===o[e]:o[e]&&t.toLowerCase()===o[e].toLowerCase()))},this.convertArr2Disable=t=>{var e;const r=[],{skuObjArr:i=[],skuArrField:n,checkedIndexArr:s=[],combineSkuArr:_=[],disabledArr:o=[],combineSeparator:a="-",combineSkuField:u="id"}=t;for(let t=0;t<i.length;t++){const l=n?(null===(e=i[t])||void 0===e?void 0:e[n])||[]:i[t]||[];Array.isArray(r[t])||(r[t]=[]);for(let e=0;e<l.length;e++){const i=s.slice(0,t),n=s.slice(t+1),l=i.concat(e).concat(n).join(a),h=_.filter(t=>this.checkPattern({str:t[u],likeStr:l,separator:a})),c=o.map(t=>{const{field:e,disabledFun:r,disabledFieldValue:i}=t,n=h.some(t=>r(t));return{[e]:n?i:!i}}).reduce((t,e)=>Object.assign(Object.assign({},t),e),{});r[t][e]=c}}return r},this.createSingleTon=t=>{let e=null;const r=new Proxy(t,{construct:(t,r)=>e||(e="undefined"!=typeof Reflect&&Reflect.construct?Reflect.construct(t,r):new t(...r),e)});return r.prototype.constructor=r,r},this.findDeepValue=t=>{const{list:e,selected:r,selectedValueInListFieldName:i,childrenFieldName:n}=t;if(!r.length)return;const s=r[r.length-1],_=t=>{for(const e of t){if(e[i]===s)return e;const t=e[n];if(Array.isArray(t)&&t.length){const e=_(t);if(e)return e}}};return _(e)}}before_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_lt_hour"})}before_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"before_gt_hour"})}after_lt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_lt_hour"})}after_gt_hour(t=Date.now(),e=1){return this.__compare_time({date:t,hour:e,type:"after_gt_hour"})}is_current_year(t){const e=this.__date2timestamp(t);return(new Date).getFullYear()===new Date(e).getFullYear()}get_time_obj(t){const e=this.__date2timestamp(t),r=new Date(e),i=this.__get_suffix2(r.getMonth()+1),n=this.__get_suffix2(r.getDate()),s=this.__get_suffix2(r.getHours()),_=this.__get_suffix2(r.getMinutes()),o=this.__get_suffix2(r.getSeconds());return{year:String(r.getFullYear()),month:i,day:n,hour:s,minute:_,seconds:o,day_of_week:String(r.getDay())}}format_count({num:t=0,decimal:e=1,divide:r=1e4,suffix:i="万",show_suffix_always:n=!1}){if(!t)return 0;if(r<=0||e<0)return n?`${t} ${i}`:t;const s=parseFloat(t);if(s<=0)return n?`${s} ${i}`:s;if(s>0&&s<r)return n?`${s} ${i}`:s;const[_,o]=(s/r).toFixed(e).split(".");return o&&0!==parseFloat(o)?`${_}.${o} ${i}`:`${_} ${i}`}format_num2date(t=Date.now()){const e=parseInt(t/1e3/60/60/24%24),r=parseInt(t/1e3/60/60%24),i=parseInt(t/1e3/60%60),n=parseInt(t/1e3%60);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down_by_remain_seconds(e=t,r=60){let i;clearTimeout(i);let n=1e3*r,s=this.format_num2date(n),_={remain:n,obj:s};e(_);let o=this;return function e(r=0,a=t,u=1e3,l=0,h=Date.now()){if(r<=0)return clearTimeout(i),o=null,i=null,n=null,s=null,_=null,void a({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{l+=1,r-=1e3;let t=o.format_num2date(r);a({remain:r,obj:t});let i=1e3-(Date.now()-(h+1e3*l));i<0&&(i=0),e(r,a,i,l,h)},u)}(n,e,1e3),()=>{clearTimeout(i),o=null,i=null,n=null,s=null,_=null}}format_timestamp_to_day_hour_minute_second(t=Date.now()){const e=Math.floor(t/864e5),r=Math.floor(t%864e5/36e5),i=Math.floor(t%36e5/6e4),n=Math.floor(t%6e4/1e3);return{day:this.__get_suffix2(e),hour:this.__get_suffix2(r),minute:this.__get_suffix2(i),seconds:this.__get_suffix2(n)}}count_down(e=Date.now(),r=t){let i;clearTimeout(i);let n=this,s=this.__date2timestamp(e),_=s-Date.now(),o=this.format_timestamp_to_day_hour_minute_second(_),a={remain:_,obj:o};return r(a),function e(r=0,u=t,l=1e3,h=0,c=Date.now()){if(r<=0)return clearTimeout(i),i=null,n=null,s=null,_=null,o=null,a=null,void u({remain:0,obj:{day:"00",hour:"00",minute:"00",seconds:"00"}});clearTimeout(i),i=setTimeout(()=>{h+=1,r-=1e3;let t=n.format_timestamp_to_day_hour_minute_second(r);u({remain:r,obj:t});let i=1e3-(Date.now()-(c+1e3*h));i<0&&(i=0),e(r,u,i,h,c)},l)}(_,r,1e3),()=>{clearTimeout(i),i=null,n=null,s=null,_=null,o=null,a=null}}add(t=1,e=Date.now()){return this.__date2timestamp(e)+60*t*60*1e3}format_thousandth(t,e=2){try{const r=parseFloat(t),i=r.toString().split(".");let n=!1,s="";i[1]&&(s=i[1].replace(/0+$/,""),n=s.length>0);let _=0;n&&(_=void 0!==e?e:s.length);const o=r.toFixed(_).split("."),a=(o[0]||"").replace(/(\d)(?=(\d{3})+$)/g,"$1,");return o[1]?`${a}.${o[1]}`:a}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(t){return null==t||("String"===this.__get_type(t)?!t.trim():"Array"===this.__get_type(t)?!t.length:"Object"===this.__get_type(t)&&!Object.keys(t).length)}poll(t,e=1){let r;if(!this.__is_function(t))return()=>{clearTimeout(r),r=void 0};const i=60*e*1e3,n=()=>{t(),r=setTimeout(n,i)};return n(),()=>{clearTimeout(r),r=void 0}}is_equal(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const s=Object.keys(t),_=Object.keys(e);return 0===s.length&&0===_.length||s.length===_.length&&s.every(i=>{const n=this.__is_array(t[i])||this.__is_object(t[i]),s=this.__is_array(e[i])||this.__is_object(e[i]);return n&&s?this.is_equal(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}contains(t,e,r=!1){const i=this.__is_array(t)||this.__is_object(t),n=this.__is_array(e)||this.__is_object(e);if(!i||!n)return r?t===e:t==e;const s=Object.keys(t),_=Object.keys(e);return 0===_.length||!(0===s.length||s.length<_.length)&&_.every(i=>{if(s.indexOf(i)<0)return!1;const n=this.__is_array(t[i])||this.__is_object(t[i]),_=this.__is_array(e[i])||this.__is_object(e[i]);return n&&_?this.contains(t[i],e[i],r):r?t[i]===e[i]:t[i]==e[i]})}};export{e as default,e as helper};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
interface FindDeepValueOptions<T, K> {
|
|
2
|
+
list: T[];
|
|
3
|
+
selected: (string | number)[];
|
|
4
|
+
selectedValueInListFieldName: K;
|
|
5
|
+
childrenFieldName: K;
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
type DateType = number | string | Date;
|
|
2
9
|
type CompareType = "before_lt_hour" | "before_gt_hour" | "after_lt_hour" | "after_gt_hour";
|
|
3
10
|
interface GetTimeObj {
|
|
@@ -102,6 +109,7 @@ declare class Helper {
|
|
|
102
109
|
[key: string]: boolean;
|
|
103
110
|
}[][];
|
|
104
111
|
createSingleTon: <T extends Constructor>(className: T) => T;
|
|
112
|
+
findDeepValue: <T extends Record<string, any>, K extends Extract<keyof T, string>>(options: FindDeepValueOptions<T, K>) => T | undefined;
|
|
105
113
|
}
|
|
106
114
|
declare const helper: Helper;
|
|
107
115
|
|