把几个基础小功能迁移到独立的 sol.tool 库中
This commit is contained in:
parent
e35794ced1
commit
dc4cf12c08
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 以'#'开始的行,被视为注释.
|
||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
.vscode
|
||||||
|
.svn
|
||||||
|
~*
|
||||||
|
.gitattributes
|
||||||
|
dump.rdb
|
16
.prettierrc.js
Normal file
16
.prettierrc.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
对 VSCode Prettier 有效;建议一直要有本配置文件,否则不同版本的 Prettier 的默认配置会不同,例如 TrailingComma
|
||||||
|
对 VSCode Prettier Standard 无效,似乎是集成了不能修改的配置。
|
||||||
|
*/
|
||||||
|
module.exports = {
|
||||||
|
printWidth: 160, // default 80
|
||||||
|
tabWidth: 2, // default 2
|
||||||
|
useTabs: false,
|
||||||
|
semi: false, // default true
|
||||||
|
singleQuote: true, // default false
|
||||||
|
trailingComma: 'es5', // none (default in v 1.*), es5 (default in v2.0.0), all
|
||||||
|
bracketSpacing: true, // default true
|
||||||
|
jsxBracketSameLine: false, // default false
|
||||||
|
arrowParens: 'always', // avoid (default in v1.9.0), always (default since v2.0.0)
|
||||||
|
quoteProps: 'as-needed', // as-needed (default), consistent, preserve
|
||||||
|
}
|
25
index.js
Normal file
25
index.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* 基础小工具,可通用于服务端和用户端
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
sleep: (ms) => new Promise((resolve, reject) => setTimeout(resolve, ms)),
|
||||||
|
parseJsonPossible(value) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(value)
|
||||||
|
} catch (e) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sortAndFilterJson({ fields, entity, exclude = [] } = {}) {
|
||||||
|
const newEntity = {}
|
||||||
|
for (let key of Object.keys(fields).sort()) {
|
||||||
|
if (typeof (entity[key] !== 'undefined') && !Number.isNaN(entity[key]) && entity[key] !== Infinity) {
|
||||||
|
newEntity[key] = entity[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let exkey of exclude) {
|
||||||
|
delete newEntity[exkey]
|
||||||
|
}
|
||||||
|
return JSON.stringify(newEntity)
|
||||||
|
},
|
||||||
|
}
|
13
package.json
Normal file
13
package.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"name": "sol.tool",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"setup": "npm install"
|
||||||
|
},
|
||||||
|
"author": ""
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user