| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ForData=e():t.ForData=e()}(self,(()=>{return t={10:(t,e,r)=>{const n=r(706),o=r(582),s=r(961),h=r(639);t.exports={Tree:n,DateTime:o,Encode:s,EasyArray:h}},582:t=>{t.exports=class{constructor(){return this.format(),this.getDays(),this.prev(),this.prevDay(),this.prevMonth(),this.prevYear(),this.next(),this.nextDay(),this.nextMonth(),this.nextYear(),this.getWeek(),this.getRangeYear(),this.getRangeMonth(),this.getRangeWeek(),this}prev(){Date.prototype.prev=function(t){return new Date(+this-t).format("yyyy-MM-dd hh:mm:ss")}}prevDay(){Date.prototype.prevDay=function(t={day:1,isShowAll:!1,includeCurrent:!1}){let{day:e=1,isShowAll:r=!1,includeCurrent:n=!1}=t;if(!r&&!n)return new Date(+this-1e3*e*60*60*24).format("yyyy-MM-dd hh:mm:ss");let o=[];for(let t=+!n;t<=e-+n;t++)o.unshift(new Date(+this-1e3*t*60*60*24)),1===e&&o.unshift(new Date(+this-864e5));return o.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}}prevMonth(){Date.prototype.prevMonth=function(t={month:1,isShowAll:!1,includeCurrent:!1}){let{month:e=1,isShowAll:r=!1,includeCurrent:n=!1}=t,o=this.getMonth()+1,s=this.getDays(),h=new Date(this.format("yyyy-MM-01 hh:mm:ss"));h.setMonth(h.getMonth()-e);let i=h.getDays();if(!r&&!n)return new Date(h.format(`yyyy-MM-${s>i?i:s} ${this.format(" hh:mm:ss")}`)).format("yyyy-MM-dd hh:mm:ss");let a=[];for(let t=1;t<=e;t++){h.setMonth(o-t-+!n),i=h.getDays();let e=new Date(h.format(`yyyy-MM-${s>i?i:s} ${this.format(" hh:mm:ss")}`));a.unshift(e)}return a.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}}prevYear(){Date.prototype.prevYear=function(t={year:1,isShowAll:!1,includeCurrent:!1}){let{year:e=1,isShowAll:r=!1,includeCurrent:n=!1}=t,o=this.getFullYear();if(!r&&!n)return new Date(this.setFullYear(o-e)).format("yyyy-MM-dd hh:mm:ss");let s=[];for(let t=0;t<e;t++)s.unshift(new Date(this.setFullYear(o-t-+!n)));return s.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}}next(){Date.prototype.next=function(t){return new Date(+this+t).format("yyyy-MM-dd hh:mm:ss")}}nextDay(){Date.prototype.nextDay=function(t={day:1,isShowAll:!1,includeCurrent:!1}){let{day:e=1,isShowAll:r=!1,includeCurrent:n=!1}=t;if(!r&&!n)return new Date(+this+1e3*e*60*60*24).format("yyyy-MM-dd hh:mm:ss");let o=[];for(let t=+!n;t<=e-+n;t++)o.push(new Date(+this+1e3*t*60*60*24)),1===e&&o.push(new Date(+this+864e5));return o.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}}nextMonth(){Date.prototype.nextMonth=function(t={month:1,isShowAll:!1,includeCurrent:!1}){let{month:e=1,isShowAll:r=!1,includeCurrent:n=!1}=t,o=this.getDays();if(!r&&!n){let t=new Date(this.format("yyyy-MM-01 hh:mm:ss"));t.setMonth(t.getMonth()+e);let r=t.getDays();return new Date(t.format(`yyyy-MM-${o>r?r:o} ${this.format(" hh:mm:ss")}`)).format("yyyy-MM-dd hh:mm:ss")}let s=[];for(let t=1;t<=e;t++){let e=new Date(this.format("yyyy-MM-01 hh:mm:ss"));e.setMonth(e.getMonth()+t-+n);let r=e.getDays(),h=new Date(e.format(`yyyy-MM-${o>r?r:o} ${this.format(" hh:mm:ss")}`));s.push(h)}return s.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}}nextYear(){Date.prototype.nextYear=function(t={year:1,isShowAll:!1,includeCurrent:!1}){let{year:e=1,isShowAll:r=!1,includeCurrent:n=!1}=t,o=this.getFullYear();if(!r&&!n)return new Date(this.setFullYear(o+e)).format("yyyy-MM-dd hh:mm:ss");let s=[];for(let t=+!n+0;t<e+ +!n;t++)s.push(new Date(this.setFullYear(o+t)));return s.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}}split(t={}){let{startTime:e,endTime:r,gap:n}=t,o=[],s=Math.floor(+r-+e)/n;for(let t=0;t<=s;t++)o.push(new Date(+e+n*t));return o.map((t=>t.format("yyyy-MM-dd hh:mm:ss")))}format(){Date.prototype.format=function(t){let e={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length)));for(let r in e)new RegExp("("+r+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?e[r]:("00"+e[r]).substr((""+e[r]).length)));return t}}calc(t={}){let{startTime:e,endTime:r,offset:n=8,type:o="year"}=t;if("year"===o){let t=new Date(Math.abs(+r-+e)-1e3*n*3600);return{year:t.getFullYear()-1970,month:t.getMonth(),day:t.getDate()-1,hour:t.getHours(),minutes:t.getMinutes(),seconds:t.getSeconds()}}if("day"===o){let t=Math.abs(+r-+e),o=Math.floor(t/864e5),s=new Date(t-24*o*36e5-1e3*n*3600);return{day:o,hour:s.getHours(),minutes:s.getMinutes(),seconds:s.getSeconds()}}}getWeek(){Date.prototype.getWeek=function(t=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]){return t[this.getDay()]}}getRangeYear(){Date.prototype.getRangeYear=function(){let t=this.getFullYear();return{start:`${t}-01-01 00:00:00`,end:`${t}-12-31 23:59:59`}}}getRangeMonth(){Date.prototype.getRangeMonth=function(){let t=this.format("yyyy-MM-01 00:00:00"),e=new Date(+new Date(this.format(`yyyy-${this.getMonth()+2}-01 00:00:00`))-1).getDate();return{start:t,end:new Date(t).format(`yyyy-MM-${e} 23:59:59`)}}}getRangeWeek(){Date.prototype.getRangeWeek=function(){let t=this.getDay();return{start:new Date(+this-3600*(t-1)*1e3*24).format("yyyy-MM-dd 00:00:00"),end:new Date(+this+3600*(7-t)*1e3*24).format("yyyy-MM-dd 23:59:59")}}}getDays(){Date.prototype.getDays=function(){return new Date(+new Date(this.format(`yyyy-${this.getMonth()+2}-01 00:00:00`))-1).getDate()}}}},639:t=>{t.exports=class{constructor(){Array.prototype.create=this.create,Array.prototype.asc=this.asc,Array.prototype.desc=this.desc,Array.prototype.sum=this.sum,Array.prototype.unique=this.unique,Array.prototype.groupByLength=this.groupByLength,Array.prototype.groupByName=this.groupByName}create(t=1,e=(()=>null)){return Array.from({length:t},((t,r)=>e(r)))}asc(t){return t?this.sort(((e,r)=>e[t]-r[t])):this.sort(((t,e)=>t-e))}desc(t){return t?this.sort(((e,r)=>r[t]-e[t])):this.sort(((t,e)=>e-t))}sum(t){if(t){let e=0;return this.forEach((r=>e+=r[t]||0)),e}return this.reduce(((t,e)=>+t+ +e))}unique(t){if(t){let e=[];return this.forEach(((r,n)=>{e.includes(r[t])?this.splice(n,1):e.push(r[t])})),this}return[...new Set(this)]}groupByLength(t=1){let e=[];for(let r=0;r<Math.ceil(this.length/t);r++){let n=JSON.parse(JSON.stringify(this));e.push(n.splice(t*r,t))}return e}groupByName(t){let e={others:[]};return this.forEach((r=>{void 0!==r[t]?e[t]?e[t].push(r):e[t]=[r]:e.others.push(r)})),Object.values(e).reverse()}}},961:t=>{t.exports=class{constructor(){String.prototype.toBase64=this.toBase64,String.prototype.toStr=this.toStr,String.prototype.toEntity=this.toEntity,String.prototype.entityToString=this.entityToString,String.prototype.encodeURL=this.encodeURL,String.prototype.decodeURL=this.decodeURL}toBase64(){return btoa(String.fromCharCode(...(new TextEncoder).encode(this)))}base64ToString(){return(new TextDecoder).decode(Uint8Array.from(atob(this),(t=>t.charCodeAt(0))))}toEntity(){let t=[];for(let e=this.length-1;e>=0;e--)t.unshift(["&#",this[e].charCodeAt(),";"].join(""));return t.join("")}entityToString(){return this.replace(/&#(\d+);/g,(function(t,e){return String.fromCharCode(e)}))}encodeURL(){return encodeURIComponent(this)}decodeURL(){return decodeURIComponent(this)}}},706:t=>{t.exports=class{constructor(t={}){let e=this,{label:r="label",id:n="id",parentId:o="parentId",children:s="children"}=t;this.props={label:r,id:n,parentId:o,children:s},Array.prototype.toTree=function(t){return e.toTree(this,t)},Array.prototype.toArray=function(t){return e.toArray(this,t)},Array.prototype.findPath=function(t){return e.findPath(this.toArray(),t)},Array.prototype.findChildren=function(t){return e.findChildren(this.toArray(),t)}}toTree(t,e){let{id:r,parentId:n,children:o}=this.props;const s=t.filter((t=>t[n]===e));if(s.length)return s.map((e=>({...e,[o]:this.toTree(t,e[r])})))}toArray(t,e){let r=[],{label:n,id:o,parentId:s,children:h}=this.props;for(let i of t){let t={...i,[n]:i[n],[s]:e,[o]:i[o]};delete t[h],r.push(t),i[h]&&(r=[...r,...this.toArray(i[h],i[o])])}return r}findPath(t,e){let r=[],{id:n,parentId:o}=this.props;return t.forEach((s=>{s[n]===e&&(r.unshift(s),r=[...this.findPath(t,s[o]),...r])})),r}findChildren(t,e){let r=[],{id:n,parentId:o}=this.props;return t.forEach((s=>{s[o]===e&&(r.push(s),r=[...r,...this.findChildren(t,s[n])])})),r}}}},e={},function r(n){var o=e[n];if(void 0!==o)return o.exports;var s=e[n]={exports:{}};return t[n](s,s.exports,r),s.exports}(10);var t,e})); |
| module.exports = class { | ||
| constructor() { | ||
| this.format() | ||
| this.getDays() | ||
| this.prev() | ||
| this.prevDay() | ||
| this.prevMonth() | ||
| this.prevYear() | ||
| this.next() | ||
| this.nextDay() | ||
| this.nextMonth() | ||
| this.nextYear() | ||
| this.getWeek() | ||
| this.getRangeYear() | ||
| this.getRangeMonth() | ||
| this.getRangeWeek() | ||
| return this | ||
| } | ||
| prev() { | ||
| Date.prototype.prev = function(timestamp) { | ||
| return new Date(+this - timestamp).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| } | ||
| prevDay() { | ||
| Date.prototype.prevDay = function(options = { day: 1, isShowAll: false, includeCurrent: false }) { | ||
| let { day = 1, isShowAll = false, includeCurrent = false } = options | ||
| if ((!isShowAll) && !includeCurrent) { | ||
| return new Date(+this - day * 1e3 * 60 * 60 * 24).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| let results = [] | ||
| for (let i = +!includeCurrent; i <= day - +includeCurrent; i++) { | ||
| results.unshift(new Date(+this - i * 1e3 * 60 * 60 * 24)) | ||
| // day is 1 unshift prev 1 day | ||
| if (day === 1) { | ||
| results.unshift(new Date(+this - 1 * 1e3 * 60 * 60 * 24)) | ||
| } | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| } | ||
| prevMonth() { | ||
| Date.prototype.prevMonth = function(options = { month: 1, isShowAll: false, includeCurrent: false }) { | ||
| let { month = 1, isShowAll = false, includeCurrent = false } = options | ||
| let currentMonth = this.getMonth() + 1 | ||
| let days = this.getDays() | ||
| let tmpDate = new Date(this.format('yyyy-MM-01 hh:mm:ss')) | ||
| tmpDate.setMonth(tmpDate.getMonth() - month) | ||
| let tmpDateDays = tmpDate.getDays() | ||
| if ((!isShowAll) && !includeCurrent) { | ||
| return new Date(tmpDate.format(`yyyy-MM-${days > tmpDateDays ? tmpDateDays : days} ${this.format(' hh:mm:ss')}`)).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| let results = [] | ||
| for (let i = 1; i <= month; i++) { | ||
| tmpDate.setMonth(currentMonth - i - +!includeCurrent) | ||
| tmpDateDays = tmpDate.getDays() | ||
| let date = new Date(tmpDate.format(`yyyy-MM-${days > tmpDateDays ? tmpDateDays : days} ${this.format(' hh:mm:ss')}`)) | ||
| results.unshift(date) | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| } | ||
| prevYear() { | ||
| Date.prototype.prevYear = function(options = { year: 1, isShowAll: false, includeCurrent: false }) { | ||
| let { year = 1, isShowAll = false, includeCurrent = false } = options | ||
| let currentYear = this.getFullYear() | ||
| if ((!isShowAll) && !includeCurrent) { | ||
| return new Date(this.setFullYear(currentYear - year)).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| let results = [] | ||
| for (let i = 0; i < year; i++) { | ||
| results.unshift(new Date(this.setFullYear(currentYear - i - +!includeCurrent))) | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| } | ||
| next() { | ||
| Date.prototype.next = function(timestamp) { | ||
| return new Date(+this + timestamp).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| } | ||
| nextDay() { | ||
| Date.prototype.nextDay = function(options = { day: 1, isShowAll: false, includeCurrent: false }) { | ||
| let { day = 1, isShowAll = false, includeCurrent = false } = options | ||
| if ((!isShowAll) && !includeCurrent) { | ||
| return new Date(+this + day * 1e3 * 60 * 60 * 24).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| let results = [] | ||
| for (let i = +!includeCurrent; i <= day - +includeCurrent; i++) { | ||
| results.push(new Date(+this + i * 1e3 * 60 * 60 * 24)) | ||
| // day is 1 push next 1 day | ||
| if (day === 1) { | ||
| results.push(new Date(+this + 1 * 1e3 * 60 * 60 * 24)) | ||
| } | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| } | ||
| nextMonth() { | ||
| Date.prototype.nextMonth = function(options = { month: 1, isShowAll: false, includeCurrent: false }) { | ||
| let { month = 1, isShowAll = false, includeCurrent = false } = options | ||
| let days = this.getDays() | ||
| if ((!isShowAll) && !includeCurrent) { | ||
| let tmpDate = new Date(this.format('yyyy-MM-01 hh:mm:ss')) | ||
| tmpDate.setMonth(tmpDate.getMonth() + month) | ||
| let tmpDateDays = tmpDate.getDays() | ||
| return new Date(tmpDate.format(`yyyy-MM-${days > tmpDateDays ? tmpDateDays : days} ${this.format(' hh:mm:ss')}`)).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| let results = [] | ||
| for (let i = 1; i <= month; i++) { | ||
| let tmpDate = new Date(this.format('yyyy-MM-01 hh:mm:ss')) | ||
| tmpDate.setMonth(tmpDate.getMonth() + i - +includeCurrent) | ||
| let tmpDateDays = tmpDate.getDays() | ||
| let date = new Date(tmpDate.format(`yyyy-MM-${days > tmpDateDays ? tmpDateDays : days} ${this.format(' hh:mm:ss')}`)) | ||
| results.push(date) | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| } | ||
| nextYear() { | ||
| Date.prototype.nextYear = function(options = { year: 1, isShowAll: false, includeCurrent: false }) { | ||
| let { year = 1, isShowAll = false, includeCurrent = false } = options | ||
| let currentYear = this.getFullYear() | ||
| if ((!isShowAll) && !includeCurrent) { | ||
| return new Date(this.setFullYear(currentYear + year)).format('yyyy-MM-dd hh:mm:ss') | ||
| } | ||
| let results = [] | ||
| for (let i = 0 + +!includeCurrent; i < year + +!includeCurrent; i++) { | ||
| results.push(new Date(this.setFullYear(currentYear + i))) | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| } | ||
| split(options = {}) { | ||
| let { startTime, endTime, gap } = options | ||
| let results = [] | ||
| let n = Math.floor(+endTime - +startTime) / gap | ||
| for (let i = 0; i <= n; i++) { | ||
| results.push(new Date(+startTime + gap * i)) | ||
| } | ||
| return results.map(item => item.format('yyyy-MM-dd hh:mm:ss')) | ||
| } | ||
| format() { | ||
| Date.prototype.format = function(fmt) { | ||
| let o = { | ||
| 'M+': this.getMonth() + 1, //月份 | ||
| 'd+': this.getDate(), //日 | ||
| 'h+': this.getHours(), //小时 | ||
| 'm+': this.getMinutes(), //分 | ||
| 's+': this.getSeconds(), //秒 | ||
| 'q+': Math.floor((this.getMonth() + 3) / 3), //季度 | ||
| S: this.getMilliseconds() //毫秒 | ||
| } | ||
| if (/(y+)/.test(fmt)) | ||
| fmt = fmt.replace( | ||
| RegExp.$1, | ||
| (this.getFullYear() + '').substr(4 - RegExp.$1.length) | ||
| ) | ||
| for (let k in o) | ||
| if (new RegExp('(' + k + ')').test(fmt)) | ||
| fmt = fmt.replace( | ||
| RegExp.$1, | ||
| RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length) | ||
| ) | ||
| return fmt | ||
| } | ||
| } | ||
| calc(options = {}) { | ||
| let { startTime, endTime, offset = 8, type = 'year' } = options | ||
| if (type === 'year') { | ||
| let date = new Date(Math.abs(+endTime - +startTime) - offset * 1e3 * 3600) | ||
| return { | ||
| year: date.getFullYear() - 1970, | ||
| month: date.getMonth(), | ||
| day: date.getDate() - 1, | ||
| hour: date.getHours(), | ||
| minutes: date.getMinutes(), | ||
| seconds: date.getSeconds() | ||
| } | ||
| } | ||
| if (type === 'day') { | ||
| let timestamp = Math.abs(+endTime - +startTime) | ||
| let day = Math.floor(timestamp / (24 * 3600e3)) | ||
| let date = new Date(timestamp - day * 24 * 3600e3 - offset * 1e3 * 3600) | ||
| return { | ||
| day, | ||
| hour: date.getHours(), | ||
| minutes: date.getMinutes(), | ||
| seconds: date.getSeconds() | ||
| } | ||
| } | ||
| } | ||
| getWeek() { | ||
| Date.prototype.getWeek = function(weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']) { | ||
| return weeks[this.getDay()] | ||
| } | ||
| } | ||
| getRangeYear() { | ||
| Date.prototype.getRangeYear = function() { | ||
| let year = this.getFullYear() | ||
| return { | ||
| start: `${year}-01-01 00:00:00`, | ||
| end: `${year}-12-31 23:59:59` | ||
| } | ||
| } | ||
| } | ||
| getRangeMonth() { | ||
| Date.prototype.getRangeMonth = function() { | ||
| let startTime = this.format('yyyy-MM-01 00:00:00') | ||
| let days = new Date(+new Date(this.format(`yyyy-${this.getMonth() + 2}-01 00:00:00`)) - 1).getDate() | ||
| return { | ||
| start: startTime, | ||
| end: new Date(startTime).format(`yyyy-MM-${days} 23:59:59`) | ||
| } | ||
| } | ||
| } | ||
| getRangeWeek() { | ||
| Date.prototype.getRangeWeek = function() { | ||
| let day = this.getDay() | ||
| return { | ||
| start: new Date(+this - (day - 1) * 3600 * 1e3 * 24).format('yyyy-MM-dd 00:00:00'), | ||
| end: new Date(+this + ((7 - day) * 3600 * 1e3 * 24)).format('yyyy-MM-dd 23:59:59') | ||
| } | ||
| } | ||
| } | ||
| getDays() { | ||
| Date.prototype.getDays = function() { | ||
| return new Date(+new Date(this.format(`yyyy-${this.getMonth() + 2}-01 00:00:00`)) - 1).getDate() | ||
| } | ||
| } | ||
| } |
| module.exports = class { | ||
| constructor() { | ||
| Array.prototype.create = this.create | ||
| Array.prototype.asc = this.asc | ||
| Array.prototype.desc = this.desc | ||
| Array.prototype.sum = this.sum | ||
| Array.prototype.unique = this.unique | ||
| Array.prototype.groupByLength = this.groupByLength | ||
| Array.prototype.groupByName = this.groupByName | ||
| } | ||
| // 创建数组 | ||
| create(length = 1, cb = () => null) { | ||
| return Array.from({ length }, (m, n) => cb(n)) | ||
| } | ||
| // 升序 | ||
| asc(name) { | ||
| if (name) { | ||
| return this.sort((m, n) => m[name] - n[name]) | ||
| } | ||
| return this.sort((m, n) => m - n) | ||
| } | ||
| // 降序 | ||
| desc(name) { | ||
| if (name) { | ||
| return this.sort((m, n) => n[name] - m[name]) | ||
| } | ||
| return this.sort((m, n) => n - m) | ||
| } | ||
| // 求和 | ||
| sum(name) { | ||
| if (name) { | ||
| let total = 0 | ||
| this.forEach(item => total += item[name] || 0) | ||
| return total | ||
| } | ||
| return this.reduce((m, n) => { | ||
| return +m + +n | ||
| }) | ||
| } | ||
| // 去重 | ||
| unique(name) { | ||
| if (name) { | ||
| let results = [] | ||
| this.forEach((item, index) => { | ||
| if (!results.includes(item[name])) { | ||
| results.push(item[name]) | ||
| } else { | ||
| this.splice(index, 1) | ||
| } | ||
| }) | ||
| return this | ||
| } | ||
| return [...new Set(this)] | ||
| } | ||
| // 按长度分组 | ||
| groupByLength(length = 1) { | ||
| let result = [] | ||
| for (let i = 0; i < Math.ceil(this.length / length); i++) { | ||
| let tmp = JSON.parse(JSON.stringify(this)) | ||
| result.push(tmp.splice(length * i, length)) | ||
| } | ||
| return result | ||
| } | ||
| // 按字段分组 | ||
| groupByName(name) { | ||
| let result = { | ||
| others: [] | ||
| } | ||
| this.forEach(item => { | ||
| if (item[name] !== undefined) { | ||
| if (result[name]) { | ||
| result[name].push(item) | ||
| } else { | ||
| result[name] = [item] | ||
| } | ||
| } else { | ||
| result.others.push(item) | ||
| } | ||
| }) | ||
| return Object.values(result).reverse() | ||
| } | ||
| } |
| module.exports = class { | ||
| constructor() { | ||
| String.prototype.toBase64 = this.toBase64 | ||
| String.prototype.toStr = this.toStr | ||
| String.prototype.toEntity = this.toEntity | ||
| String.prototype.entityToString = this.entityToString | ||
| String.prototype.encodeURL = this.encodeURL | ||
| String.prototype.decodeURL = this.decodeURL | ||
| } | ||
| // String转Base64 | ||
| toBase64() { | ||
| return btoa(String.fromCharCode(...new TextEncoder().encode(this))) | ||
| } | ||
| // Base64转String | ||
| base64ToString() { | ||
| return new TextDecoder().decode(Uint8Array.from(atob(this), (c) => c.charCodeAt(0))) | ||
| } | ||
| // String转HTML实体 | ||
| toEntity() { | ||
| let encode = []; | ||
| for (let i = this.length - 1; i >= 0; i--) { | ||
| encode.unshift(['&#', this[i].charCodeAt(), ';'].join('')); | ||
| } | ||
| return encode.join(''); | ||
| } | ||
| // HTML实体转String | ||
| entityToString() { | ||
| return this.replace(/&#(\d+);/g, function(match, decode) { | ||
| return String.fromCharCode(decode) | ||
| }) | ||
| } | ||
| // URL编码 | ||
| encodeURL() { | ||
| return encodeURIComponent(this) | ||
| } | ||
| // URL解码 | ||
| decodeURL() { | ||
| return decodeURIComponent(this) | ||
| } | ||
| } |
| module.exports = class { | ||
| constructor(props = {}) { | ||
| let _this = this | ||
| let { label = 'label', id = 'id', parentId = 'parentId', children = 'children' } = props | ||
| this.props = { | ||
| label, | ||
| id, | ||
| parentId, | ||
| children | ||
| } | ||
| Array.prototype.toTree = function (parentId) { | ||
| return _this.toTree(this, parentId) | ||
| } | ||
| Array.prototype.toArray = function (parentId) { | ||
| return _this.toArray(this, parentId) | ||
| } | ||
| Array.prototype.findPath = function (id) { | ||
| return _this.findPath(this.toArray(), id) | ||
| } | ||
| Array.prototype.findChildren = function (id) { | ||
| return _this.findChildren(this.toArray(), id) | ||
| } | ||
| } | ||
| // 数组转树形 | ||
| toTree(arr, parentId) { | ||
| let { id, parentId: parentIdName, children: childrenName } = this.props | ||
| const children = arr.filter(node => node[parentIdName] === parentId); | ||
| if (!children.length) { | ||
| return | ||
| } | ||
| return children.map(node => ({ | ||
| ...node, | ||
| [childrenName]: this.toTree(arr, node[id]) | ||
| })) | ||
| } | ||
| // 树形转数组 | ||
| toArray(dataTree, parentId) { | ||
| let result = [] | ||
| let { label, id, parentId: parentIdName, children } = this.props | ||
| for (let node of dataTree) { | ||
| let item = { ...node, [label]: node[label], [parentIdName]: parentId, [id]: node[id] } | ||
| delete item[children] | ||
| result.push(item) | ||
| if (node[children]) { | ||
| result = [...result, ...this.toArray(node[children], node[id])] | ||
| } | ||
| } | ||
| return result | ||
| } | ||
| // 树形路径查找 | ||
| findPath(dataTree, id) { | ||
| let result = [] | ||
| let { id: idName, parentId } = this.props | ||
| dataTree.forEach(item => { | ||
| if (item[idName] === id) { | ||
| result.unshift(item) | ||
| result = [...this.findPath(dataTree, item[parentId]), ...result] | ||
| } | ||
| }) | ||
| return result | ||
| } | ||
| // 树形children集合查找 | ||
| findChildren(dataTree, id) { | ||
| let result = [] | ||
| let { id: idName, parentId } = this.props | ||
| dataTree.forEach(item => { | ||
| if (item[parentId] === id) { | ||
| result.push(item) | ||
| result = [...result, ...this.findChildren(dataTree, item[idName])] | ||
| } | ||
| }) | ||
| return result | ||
| } | ||
| } |
+23
| const { DateTime } = require('../index') | ||
| let datetime = new DateTime() | ||
| // console.log('format', new Date().format('yyyy-MM-dd hh:mm:ss')) | ||
| // console.log('prev', new Date().prev(1e3 * 60 * 60 * 24)) | ||
| // console.log('prevDay', new Date().prevDay({ day: 5 })) | ||
| // console.log('prevDay', new Date().prevDay({ day: 90, isShowAll: true })) | ||
| // console.log('prevDay', new Date().prevDay({ day: 5, isShowAll: true, includeCurrent: true })) | ||
| // console.log('prevMonth', new Date('2023-07-31 16:33:00').prevMonth({ month: 5, includeCurrent: false, isShowAll: true })) | ||
| // console.log('prevYear', new Date().prevYear({ year: 5, includeCurrent: false, isShowAll: true })) | ||
| // console.log('next', new Date().next(1e3 * 60 * 60 * 24)) | ||
| // console.log('nextDay', new Date().nextDay({ day: 5 })) | ||
| // console.log('nextDay', new Date().nextDay({ day: 5, isShowAll: true })) | ||
| // console.log('nextDay', new Date().nextDay({ day: 5, isShowAll: true, includeCurrent: true })) | ||
| // console.log('nextMonth', new Date().nextMonth({ month: 5, includeCurrent: false, isShowAll: true })) | ||
| // console.log('nextYear', new Date().nextYear({ year: 5, includeCurrent: true, isShowAll: true })) | ||
| // console.log('split', datetime.split({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-01-10 23:59:59'), gap: 1e3 * 60 * 60 * 24 })) | ||
| // console.log(datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') })) | ||
| // console.log(datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') ,type : 'day'})) | ||
| // console.log(new Date().getWeek()) | ||
| // console.log(new Date().getWeek(['周日', '周一', '周二', '周三', '周四', '周五', '周六'])) | ||
| // console.log(new Date().getRangeYear()) | ||
| // console.log(new Date().getRangeMonth()) | ||
| // console.log(new Date().getRangeWeek()) |
| const { EasyArray } = require('../index') | ||
| new EasyArray() | ||
| // console.log([1, 2, 3, 4, 5, 1, 3, 4].unique()) | ||
| // console.log([{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].unique('a')) | ||
| console.log([1, 2, 3, 4, 5, 6, 7].groupByLength(2)) | ||
| console.log([{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupByName('c')) |
+58
| const { EasyTree } = require('../index') | ||
| new EasyTree({ | ||
| parentId: 'pid', | ||
| label: 'name', | ||
| children: 'child' | ||
| }) | ||
| let tree = [{ | ||
| name: '-一级 1', | ||
| id: '一级 1', | ||
| z: 1, | ||
| child: [{ | ||
| name: '-二级 1-1', | ||
| id: '二级 1-1', | ||
| z: 3, | ||
| child: [{ | ||
| name: '-三级 1-1-1', | ||
| id: '三级 1-1-1', | ||
| z: 2 | ||
| }] | ||
| }] | ||
| }, { | ||
| name: '-一级 2', | ||
| id: '一级 2', | ||
| child: [{ | ||
| name: '-二级 2-1', | ||
| id: '二级 2-1', | ||
| child: [{ | ||
| name: '-三级 2-1-1', | ||
| id: '三级 2-1-1' | ||
| }] | ||
| }, { | ||
| name: '-二级 2-2', | ||
| id: '二级 2-2', | ||
| child: [{ | ||
| name: '-三级 2-2-1', | ||
| id: '三级 2-2-1' | ||
| }] | ||
| }] | ||
| }, { | ||
| name: '-一级 3', | ||
| id: '一级 3', | ||
| child: [{ | ||
| name: '-二级 3-1', | ||
| id: '二级 3-1', | ||
| child: [{ | ||
| name: '-三级 3-1-1', | ||
| id: '三级 3-1-1' | ||
| }] | ||
| }, { | ||
| name: '-二级 3-2', | ||
| id: '二级 3-2', | ||
| child: [{ | ||
| name: '-三级 3-2-1', | ||
| id: '三级 3-2-1' | ||
| }] | ||
| }] | ||
| }] | ||
| console.log(tree.toArray().toTree().findChildren('一级 1')) |
+9
-74
@@ -1,75 +0,10 @@ | ||
| module.exports = class { | ||
| constructor(props = {}) { | ||
| let _this = this | ||
| let { label = 'label', id = 'id', parentId = 'parentId', children = 'children' } = props | ||
| this.props = { | ||
| label, | ||
| id, | ||
| parentId, | ||
| children | ||
| } | ||
| Array.prototype.toTree = function (parentId) { | ||
| return _this.toTree(this, parentId) | ||
| } | ||
| Array.prototype.toArray = function (parentId) { | ||
| return _this.toArray(this, parentId) | ||
| } | ||
| Array.prototype.findPath = function (id) { | ||
| return _this.findPath(this.toArray(), id) | ||
| } | ||
| Array.prototype.findChildren = function (id) { | ||
| return _this.findChildren(this.toArray(), id) | ||
| } | ||
| } | ||
| // 数组转树形 | ||
| toTree(arr, parentId) { | ||
| let { id, parentId: parentIdName, children: childrenName } = this.props | ||
| const children = arr.filter(node => node[parentIdName] === parentId); | ||
| if (!children.length) { | ||
| return | ||
| } | ||
| return children.map(node => ({ | ||
| ...node, | ||
| [childrenName]: this.toTree(arr, node[id]) | ||
| })) | ||
| } | ||
| // 树形转数组 | ||
| toArray(dataTree, parentId) { | ||
| let result = [] | ||
| let { label, id, parentId: parentIdName, children } = this.props | ||
| for (let node of dataTree) { | ||
| let item = { ...node, [label]: node[label], [parentIdName]: parentId, [id]: node[id] } | ||
| delete item[children] | ||
| result.push(item) | ||
| if (node[children]) { | ||
| result = [...result, ...this.toArray(node[children], node[id])] | ||
| } | ||
| } | ||
| return result | ||
| } | ||
| // 树形路径查找 | ||
| findPath(dataTree, id) { | ||
| let result = [] | ||
| let { id: idName, parentId } = this.props | ||
| dataTree.forEach(item => { | ||
| if (item[idName] === id) { | ||
| result.unshift(item) | ||
| result = [...this.findPath(dataTree, item[parentId]), ...result] | ||
| } | ||
| }) | ||
| return result | ||
| } | ||
| // 树形children集合查找 | ||
| findChildren(dataTree, id) { | ||
| let result = [] | ||
| let { id: idName, parentId } = this.props | ||
| dataTree.forEach(item => { | ||
| if (item[parentId] === id) { | ||
| result.push(item) | ||
| result = [...result, ...this.findChildren(dataTree, item[idName])] | ||
| } | ||
| }) | ||
| return result | ||
| } | ||
| const Tree = require('./src/Tree/index') | ||
| const DateTime = require('./src/DateTime/index') | ||
| const Encode = require('./src/Encode/index') | ||
| const EasyArray = require('./src/EasyArray/index') | ||
| module.exports = { | ||
| Tree, | ||
| DateTime, | ||
| Encode, | ||
| EasyArray | ||
| } |
+10
-8
| { | ||
| "name": "fordata", | ||
| "version": "1.0.0", | ||
| "description": "Easy tree data processing.", | ||
| "version": "1.0.1", | ||
| "description": "Easy data to handle by prototype", | ||
| "main": "index.js", | ||
@@ -10,13 +10,15 @@ "scripts": { | ||
| "keywords": [ | ||
| "EasyDataTree", | ||
| "fordata", | ||
| "EasyData", | ||
| "EasyTree", | ||
| "data-utils", | ||
| "treedata", | ||
| "datatree" | ||
| "datatree", | ||
| "datetime", | ||
| "format" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/z41z/easytree.git" | ||
| "url": "git+https://github.com/z41z/fordata.git" | ||
| }, | ||
| "homepage": "https://github.com/z41z/easytree#readme", | ||
| "homepage": "https://github.com/z41z/fordata#readme", | ||
| "author": "z41z", | ||
@@ -28,2 +30,2 @@ "license": "MIT", | ||
| } | ||
| } | ||
| } |
+264
-14
@@ -1,4 +0,4 @@ | ||
| # EasyTree | ||
| # ForData | ||
| Easy tree data processing. | ||
| Easy data to handle by prototype. | ||
@@ -8,3 +8,3 @@ ## Install | ||
| ``` node | ||
| npm i easydata-tree //or yarn add easydata-tree | ||
| npm i fordata //or yarn add fordata | ||
| ``` | ||
@@ -15,11 +15,3 @@ | ||
| ``` js | ||
| <script src="https://unpkg.com/easydata-tree/dist/index.min.js"></script> | ||
| <script> | ||
| new EasyTree({ | ||
| id: 'id', | ||
| parentId: 'pid', | ||
| label: 'name', | ||
| children: 'child' | ||
| }) | ||
| </script> | ||
| <script src="https://unpkg.com/fordata/dist/index.min.js"></script> | ||
| ``` | ||
@@ -29,5 +21,6 @@ | ||
| - #### Tree | ||
| ``` js | ||
| const EasyTree = require("easydata-tree") | ||
| new EasyTree({ | ||
| const { Tree } = require("fordata") | ||
| new Tree({ | ||
| id: 'id', | ||
@@ -117,2 +110,259 @@ parentId: 'pid', | ||
| tree.findPath('一级 3') | ||
| ``` | ||
| - #### DateTime | ||
| ``` js | ||
| const { DateTime } = require("fordata") | ||
| new DateTime() | ||
| ``` | ||
| - ##### format() | ||
| ``` js | ||
| new Date().format('yyyy-MM-dd hh:mm:ss') | ||
| // 2023-07-29 11:48:17 | ||
| ``` | ||
| - ##### prev() | ||
| - {Number} timestamp | ||
| ``` js | ||
| new Date().prev(1e3 * 60 * 60 * 24) | ||
| // 2023-07-28 11:48:17 | ||
| ``` | ||
| - ##### prevDay() | ||
| - {Object} options | ||
| - {Number} options.day | ||
| - {Boolean} options.isShowAll = false | ||
| - {Boolean} options.includeCurrent = false | ||
| ``` js | ||
| new Date().prevDay({ day: 5 }) | ||
| // 2023-07-24 11:48:17 | ||
| new Date().prevDay({ day: 5, isShowAll: true }) | ||
| // [ | ||
| // '2023-07-24 11:48:17', | ||
| // '2023-07-25 11:48:17', | ||
| // '2023-07-26 11:48:17', | ||
| // '2023-07-27 11:48:17', | ||
| // '2023-07-28 11:48:17' | ||
| // ] | ||
| new Date().prevDay({ day: 5, isShowAll: true, includeCurrent: true }) | ||
| // [ | ||
| // '2023-07-25 11:48:17', | ||
| // '2023-07-26 11:48:17', | ||
| // '2023-07-27 11:48:17', | ||
| // '2023-07-28 11:48:17', | ||
| // '2023-07-29 11:48:17' | ||
| // ] | ||
| ``` | ||
| - ##### prevMonth() | ||
| - {Object} options | ||
| - {Number} options.month | ||
| - {Boolean} options.isShowAll = false | ||
| - {Boolean} options.includeCurrent = false | ||
| ``` js | ||
| new Date().prevMonth({ month: 5, includeCurrent: false, isShowAll: true }) | ||
| // [ | ||
| // '2023-08-31 14:57:02', | ||
| // '2023-09-30 14:57:02', | ||
| // '2023-10-31 14:57:02', | ||
| // '2023-11-30 14:57:02', | ||
| // '2023-12-31 14:57:02' | ||
| // ] | ||
| ``` | ||
| - ##### prevYear() | ||
| - {Object} options | ||
| - {Number} options.year | ||
| - {Boolean} options.isShowAll = false | ||
| - {Boolean} options.includeCurrent = false | ||
| ``` js | ||
| new Date().prevYear({ year: 5, includeCurrent: false, isShowAll: true }) | ||
| // [ | ||
| // '2018-07-29 14:57:57', | ||
| // '2019-07-29 14:57:57', | ||
| // '2020-07-29 14:57:57', | ||
| // '2021-07-29 14:57:57', | ||
| // '2022-07-29 14:57:57' | ||
| // ] | ||
| ``` | ||
| - ##### next() | ||
| - {Number} timestamp | ||
| ``` js | ||
| new Date().next(1e3 * 60 * 60 * 24) | ||
| // 2023-07-30 14:58:50 | ||
| ``` | ||
| - ##### nextDay() | ||
| - {Object} options | ||
| - {Number} options.day | ||
| - {Boolean} options.isShowAll = false | ||
| - {Boolean} options.includeCurrent = false | ||
| ``` js | ||
| new Date().nextDay({ day: 5 }) | ||
| // 2023-08-03 14:59:09 | ||
| new Date().nextDay({ day: 5, isShowAll: true }) | ||
| // [ | ||
| // '2023-07-30 14:59:28', | ||
| // '2023-07-31 14:59:28', | ||
| // '2023-08-01 14:59:28', | ||
| // '2023-08-02 14:59:28', | ||
| // '2023-08-03 14:59:28' | ||
| // ] | ||
| new Date().nextDay({ day: 5, isShowAll: true, includeCurrent: true }) | ||
| //[ | ||
| // '2023-07-29 15:00:46', | ||
| // '2023-07-30 15:00:46', | ||
| // '2023-07-31 15:00:46', | ||
| // '2023-08-01 15:00:46', | ||
| // '2023-08-02 15:00:46' | ||
| //] | ||
| ``` | ||
| - ##### nextMonth() | ||
| - {Object} options | ||
| - {Number} options.month | ||
| - {Boolean} options.isShowAll = false | ||
| - {Boolean} options.includeCurrent = false | ||
| ``` js | ||
| new Date().nextMonth({ month: 5, includeCurrent: false, isShowAll: true }) | ||
| //[ | ||
| // '2023-08-31 15:01:24', | ||
| // '2023-09-30 15:01:24', | ||
| // '2023-10-31 15:01:24', | ||
| // '2023-11-30 15:01:24', | ||
| // '2023-12-31 15:01:24' | ||
| //] | ||
| ``` | ||
| - ##### nextYear() | ||
| - {Object} options | ||
| - {Number} options.year | ||
| - {Boolean} options.isShowAll = false | ||
| - {Boolean} options.includeCurrent = false | ||
| ``` js | ||
| new Date().nextYear({ year: 5, includeCurrent: false, isShowAll: true }) | ||
| //[ | ||
| // '2023-07-29 15:01:53', | ||
| // '2024-07-29 15:01:53', | ||
| // '2025-07-29 15:01:53', | ||
| // '2026-07-29 15:01:53', | ||
| // '2027-07-29 15:01:53' | ||
| //] | ||
| ``` | ||
| - ##### split() | ||
| - {Object} options | ||
| - {Date} options.startTime | ||
| - {Date} options.endTime | ||
| - {Number} options.gap `milliseconds` | ||
| ``` js | ||
| datetime.split({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-01-10 23:59:59'), gap: 1e3 * 60 * 60 * 24 }) | ||
| //[ | ||
| // '2022-01-01 00:00:00', | ||
| // '2022-01-02 00:00:00', | ||
| // '2022-01-03 00:00:00', | ||
| // '2022-01-04 00:00:00', | ||
| // '2022-01-05 00:00:00', | ||
| // '2022-01-06 00:00:00', | ||
| // '2022-01-07 00:00:00', | ||
| // '2022-01-08 00:00:00', | ||
| // '2022-01-09 00:00:00', | ||
| // '2022-01-10 00:00:00' | ||
| // ] | ||
| ``` | ||
| - ##### calc() | ||
| - {Object} options | ||
| - {Date} options.startTime | ||
| - {Date} options.endTime | ||
| - {type} options.type `type values 'year' or 'day', default is 'year'` | ||
| - {Number} options.offset `timezone offset, default is 8 (8 is China Timezone)` | ||
| ``` js | ||
| datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') }) | ||
| // { year: 0, month: 10, day: 9, hour: 23, minutes: 59, seconds: 59 } | ||
| datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') ,type : 'day'}) | ||
| // { day: 313, hour: 23, minutes: 59, seconds: 59 } | ||
| ``` | ||
| - ##### getWeek() | ||
| - {Array} weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'] | ||
| ``` js | ||
| new Date().getWeek() | ||
| // 星期日 | ||
| new Date().getWeek(['周日', '周一', '周二', '周三', '周四', '周五', '周六']) | ||
| // 周日 | ||
| ``` | ||
| - ##### getRangeYear() | ||
| ``` js | ||
| new Date().getRangeYear() | ||
| // { start: '2023-01-01 00:00:00', end: '2023-12-31 23:59:59' } | ||
| ``` | ||
| - ##### getRangeMonth() | ||
| ``` js | ||
| new Date().getRangeMonth() | ||
| // { start: '2023-07-01 00:00:00', end: '2023-07-31 23:59:59' } | ||
| ``` | ||
| - ##### getRangeWeek() | ||
| ``` js | ||
| new Date().getRangeWeek() | ||
| // { start: '2023-07-24 00:00:00', end: '2023-07-30 23:59:59' } | ||
| ``` | ||
| - #### Encode | ||
| ``` js | ||
| const { Encode } = require("fordata") | ||
| new Encode() | ||
| ``` | ||
| - ##### toBase64() | ||
| ``` js | ||
| "test".toBase64() | ||
| ``` | ||
| - ##### base64ToString() | ||
| ``` js | ||
| "dGVzdA==".toBase64() | ||
| ``` | ||
| - ##### toEntity() | ||
| ``` js | ||
| "test".toEntity() | ||
| ``` | ||
| - ##### entityToString() | ||
| ``` js | ||
| "test".entityToString() | ||
| ``` | ||
| - ##### encodeURL() | ||
| ``` js | ||
| "http://test.com".encodeURL() | ||
| ``` | ||
| - ##### decodeURL() | ||
| ``` js | ||
| "http%3A%2F%2Ftest.com".decodeURL() | ||
| ``` | ||
| - #### EasyArray | ||
| ``` js | ||
| const { EasyArray } = require("fordata") | ||
| new EasyArray() | ||
| ``` | ||
| - ##### create() | ||
| ``` js | ||
| new Array.create(5, (i) => i + 1) | ||
| ``` | ||
| - ##### asc() | ||
| ``` js | ||
| [1, 2, 3, 4, 5, 1, 3, 4].asc() | ||
| [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].asc('a') | ||
| ``` | ||
| - ##### desc() | ||
| ``` js | ||
| [1, 2, 3, 4, 5, 1, 3, 4].desc() | ||
| [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].desc('a') | ||
| ``` | ||
| - ##### sum() | ||
| ``` js | ||
| [1, 2, 3, 4, 5, 1, 3, 4].sum() | ||
| [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].sum('a') | ||
| ``` | ||
| - ##### unique() | ||
| ``` js | ||
| [1, 2, 3, 4, 5, 1, 3, 4].unique() | ||
| [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].unique('a') | ||
| ``` | ||
| - ##### groupByLength() | ||
| ``` js | ||
| [1, 2, 3, 4, 5, 1, 3, 4].groupByLength(2) | ||
| ``` | ||
| - ##### groupByName() | ||
| ``` js | ||
| [{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupByName('a') | ||
| ``` |
@@ -7,3 +7,3 @@ const path = require('path'); | ||
| filename: 'index.min.js', | ||
| library: 'EasyTree', | ||
| library: 'ForData', | ||
| path: path.resolve(__dirname, 'dist'), | ||
@@ -10,0 +10,0 @@ libraryTarget: 'umd' |
-58
| const EasyTree = require('./index') | ||
| new EasyTree({ | ||
| parentId: 'pid', | ||
| label: 'name', | ||
| children: 'child' | ||
| }) | ||
| let tree = [{ | ||
| name: '-一级 1', | ||
| id: '一级 1', | ||
| z: 1, | ||
| child: [{ | ||
| name: '-二级 1-1', | ||
| id: '二级 1-1', | ||
| z: 3, | ||
| child: [{ | ||
| name: '-三级 1-1-1', | ||
| id: '三级 1-1-1', | ||
| z: 2 | ||
| }] | ||
| }] | ||
| }, { | ||
| name: '-一级 2', | ||
| id: '一级 2', | ||
| child: [{ | ||
| name: '-二级 2-1', | ||
| id: '二级 2-1', | ||
| child: [{ | ||
| name: '-三级 2-1-1', | ||
| id: '三级 2-1-1' | ||
| }] | ||
| }, { | ||
| name: '-二级 2-2', | ||
| id: '二级 2-2', | ||
| child: [{ | ||
| name: '-三级 2-2-1', | ||
| id: '三级 2-2-1' | ||
| }] | ||
| }] | ||
| }, { | ||
| name: '-一级 3', | ||
| id: '一级 3', | ||
| child: [{ | ||
| name: '-二级 3-1', | ||
| id: '二级 3-1', | ||
| child: [{ | ||
| name: '-三级 3-1-1', | ||
| id: '三级 3-1-1' | ||
| }] | ||
| }, { | ||
| name: '-二级 3-2', | ||
| id: '二级 3-2', | ||
| child: [{ | ||
| name: '-三级 3-2-1', | ||
| id: '三级 3-2-1' | ||
| }] | ||
| }] | ||
| }] | ||
| console.log(tree.toArray().toTree().findChildren('一级 1')) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
36293
513.26%12
140%524
276.98%364
219.3%1
Infinity%1
Infinity%