starke
v1.0.75
Published
starke means powerful
Downloads
22
Maintainers
Readme
starke
starke means powerful
wonderful utils for javascript developer
模块简介
|名称|备注| |:-:|:-:| |CircularFormat|环形对象格式化| |Schedule|定时任务的载体| |ScheduleQueue|按顺序执行定时任务的队列| |StarkeLogger|在控制台打印多彩的日志| |Determination|Util 算法|
Example of Determination
1. isEmpty [Function]
// isEmpty support strict or loose non-empty judgment of objects
// It can effectively avoid the null pointer problem in front-end development.
const obj = {
name: '',
auhtor: '',
hobby: []
}
// false
const empty = isEmpty(obj)
// ture
const empty = isEmpty(obj, true)
2. clearObject [Function]
// Sometimes we want to keep the keys of the object while emptying the cache
let cache = {
name: 'starke',
auhtor: '4everlynn',
hobby: ['coding', 'music']
}
// after call this obj will be empty
// like {name: '', author: '', hobby: []}
// which could be judged as true by isEmpty
clearObject(obj)
3. equals [Function]
// Sometimes we want to determine whether two objects are equal in attribute values.
// this function will be usefull
let user = {
name: '4everlynn',
hobby: ['coding', 'music']
}
let cache = {
name: '4everlynn',
hobby: ['coding', 'music']
}
// false
const isEqual = user === cache
// true
const starkeEq = equals(user, cache)
// It can even handle the equality of ring objects.
// And starke create this function by hash, which is very stable
4. hash [Function]
// Get the hash code of the string
const string = 'Hello Starke'
const code = hash(string)
5. filter [Function]
// Filter array by condition
const users = [{
user: '4everlynn',
age: 20
}, {
user: 'Starke',
age: 1
}, {
user: 'Lynn',
age: 18
}]
/** result
[{
user: '4everlynn',
age: 20
}, {
user: 'Lynn',
age: 18
}]
*/
const target = filter(users, item => {
return item.age < 20
})
6. group [Function]
// group array by condition
const users = [{
user: '4everlynn',
age: 20,
role: 'admin'
}, {
user: 'Starke',
age: 1,
role: 'admin'
}, {
user: 'Lynn',
age: 18,
role: 'user'
}]
// result:
// [ [ { user: '4everlynn', age: 20, role: 'admin' },
// { user: 'Starke', age: 1, role: 'admin' } ],
// [ { user: 'Lynn', age: 18, role: 'user' } ] ]
const target = group(users, item => {
// group by 'role'
return item.role
})
7. hashColor [Function]
const category = 'Operate'
// Generate a stable RGB color based on the string
// rgb(232.2421875, 160, 244)
const color = hashColor(category)
// No matter how many times it runs, the result is the same.