ForData
Easy handle data by prototype for TreeData、Array、Date、Encode、String etc..
Install
npm i fordata //or yarn add fordata
CDN
<script src="https://unpkg.com/fordata/dist/index.min.js"></script>
Usage
const { Tree } = require("fordata")
new Tree({
id: 'id',
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'
}]
}]
}]
const { DateTime } = require("fordata")
new DateTime()
new Date().format('yyyy-MM-dd hh:mm:ss')
-
prev()
new Date().prev(1e3 * 60 * 60 * 24)
-
prevDay()
- {Object} options
- {Number} options.day
- {Boolean} options.isShowAll = false
- {Boolean} options.includeCurrent = false
new Date().prevDay({ day: 5 })
new Date().prevDay({ day: 5, isShowAll: true })
new Date().prevDay({ day: 5, isShowAll: true, includeCurrent: true })
-
prevMonth()
- {Object} options
- {Number} options.month
- {Boolean} options.isShowAll = false
- {Boolean} options.includeCurrent = false
new Date().prevMonth({ month: 5, includeCurrent: false, isShowAll: true })
-
prevYear()
- {Object} options
- {Number} options.year
- {Boolean} options.isShowAll = false
- {Boolean} options.includeCurrent = false
new Date().prevYear({ year: 5, includeCurrent: false, isShowAll: true })
-
next()
new Date().next(1e3 * 60 * 60 * 24)
-
nextDay()
- {Object} options
- {Number} options.day
- {Boolean} options.isShowAll = false
- {Boolean} options.includeCurrent = false
new Date().nextDay({ day: 5 })
new Date().nextDay({ day: 5, isShowAll: true })
new Date().nextDay({ day: 5, isShowAll: true, includeCurrent: true })
-
nextMonth()
- {Object} options
- {Number} options.month
- {Boolean} options.isShowAll = false
- {Boolean} options.includeCurrent = false
new Date().nextMonth({ month: 5, includeCurrent: false, isShowAll: true })
-
nextYear()
- {Object} options
- {Number} options.year
- {Boolean} options.isShowAll = false
- {Boolean} options.includeCurrent = false
new Date().nextYear({ year: 5, includeCurrent: false, isShowAll: true })
-
split()
- {Object} options
- {Date} options.startTime
- {Date} options.endTime
- {Number} options.gap
milliseconds
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 })
-
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)
datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') })
datetime.calc({ startTime: new Date('2022-01-01 00:00:00'), endTime: new Date('2022-11-10 23:59:59') ,type : 'day'})
-
getWeek()
- {Array} weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
new Date().getWeek()
new Date().getWeek(['周日', '周一', '周二', '周三', '周四', '周五', '周六'])
-
getRangeYear()
new Date().getRangeYear()
-
getRangeMonth()
new Date().getRangeMonth()
-
getRangeWeek(startMonday = true)
new Date().getRangeWeek()
-
Encode
const { Encode } = require("fordata")
new Encode()
"test".toBase64()
"dGVzdA==".toBase64()
"test".toEntity()
"test".entityToString()
"http://test.com".encodeURL()
"http%3A%2F%2Ftest.com".decodeURL()
-
EasyArray
const { EasyArray } = require("fordata")
new EasyArray()
new Array.create(5, (i) => i + 1)
[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')
[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')
[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')
[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')
[1, 2, 3, 4, 5, 1, 3, 4].groupByLength(2)
[{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupByName('a')
[{ a: 1 }, { b: 2 }, { a: 2 }, { a: 3 }, { a: 1 }, { b: 2 }, { b: 1 }, { c: 1 }].groupValue('a')
-
EasyString
const { EasyString } = require("fordata")
new EasyString()
'510101199911111111'.getInfoByIdCard()