From bc54df4a0eb41bff060e60cb69da86b80e6a388c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=9A=8F=E6=98=93?= Date: Sun, 1 Dec 2024 20:28:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E4=B8=8D=E5=90=8C=E7=8E=AF=E5=A2=83=E7=9A=84?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmrc | 4 +- eslint.config.js | 65 --------------- generate.js | 81 ++++++++++--------- libBrowser/url/_meta.json | 4 + {lib => libBrowser}/url/getQueryParams.js | 0 {lib => libBrowser}/url/getScriptTagSrc.js | 0 .../url/getScriptTagSrc.test.js | 0 libNode/crypto/_meta.json | 4 + .../crypto/hmacMd5.js | 0 .../md5_node.js => libNode/crypto/md5.js | 0 .../crypto/nanoid.js | 0 libNode/number/_meta.json | 4 + .../number/incrTimeID.js | 0 package.json | 30 +++---- vitest.config.mjs | 9 --- 15 files changed, 65 insertions(+), 136 deletions(-) delete mode 100644 eslint.config.js create mode 100644 libBrowser/url/_meta.json rename {lib => libBrowser}/url/getQueryParams.js (100%) rename {lib => libBrowser}/url/getScriptTagSrc.js (100%) rename {lib => libBrowser}/url/getScriptTagSrc.test.js (100%) create mode 100644 libNode/crypto/_meta.json rename lib/crypto/hmacMd5_node.js => libNode/crypto/hmacMd5.js (100%) rename lib/crypto/md5_node.js => libNode/crypto/md5.js (100%) rename lib/crypto/nanoid_node.js => libNode/crypto/nanoid.js (100%) create mode 100644 libNode/number/_meta.json rename lib/number/incrTimeID_node.js => libNode/number/incrTimeID.js (100%) delete mode 100644 vitest.config.mjs diff --git a/.npmrc b/.npmrc index 8a2e75c..46078f0 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,4 @@ registry=https://registry.npmmirror.com -# registry=https://registry.npmjs.org \ No newline at end of file +# registry=https://registry.npmjs.org +proxy=http://127.0.0.1:7890 +https-proxy=http://127.0.0.1:7890 \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index 7fc5d5d..0000000 --- a/eslint.config.js +++ /dev/null @@ -1,65 +0,0 @@ -import globals from 'globals'; -import pluginJs from '@eslint/js'; -import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; -import * as regexpPlugin from 'eslint-plugin-regexp'; -import jsdoc from 'eslint-plugin-jsdoc'; - -export default [ - { - files: ['**/*.{mjs,cjs,js}'], - languageOptions: { - globals: { - ...globals.browser, - ...globals.node - } - } - }, - pluginJs.configs.recommended, - eslintPluginPrettierRecommended, - regexpPlugin.configs['flat/recommended'], - jsdoc.configs['flat/recommended'], - { - rules: { - 'no-prototype-builtins': 'off', - 'max-len': 'off', - 'no-unused-vars': 'off', - 'linebreak-style': ['error', 'unix'], - 'jsdoc/require-jsdoc': 'off', - 'jsdoc/require-example': 1, - 'jsdoc/check-tag-names': [ - 'error', - { - definedTags: ['category'] - } - ], - 'jsdoc/sort-tags': [ - 'error', - { - linesBetween: 1, - tagSequence: [ - { - tags: [ - // - 'alias', - 'category', - 'params', - 'param', - 'return', - 'returns', - 'version', - 'deprecated', - 'since', - 'author', - 'summary', - 'describe', - 'todo', - 'example', - '-other' - ] - } - ] - } - ] - } - } -]; diff --git a/generate.js b/generate.js index bac5a42..d51182e 100644 --- a/generate.js +++ b/generate.js @@ -3,49 +3,50 @@ import { basename, resolve } from 'node:path'; import { readJsonSync } from 'fs-extra/esm'; const categories = {}; -const dirPath = 'lib'; -const fileData = []; -const libNames = []; -const dirNames = []; +['lib', 'libNode', 'libBrowser'].forEach((dirPath) => { + const fileData = []; + // const libNames = []; + const dirNames = []; -// 自动生成导出和单文件 -readdirSync(dirPath).forEach((dir) => { - dirNames.push(dir); - const metaFile = resolve(dirPath, dir, '_meta.json'); - const metaData = readJsonSync(metaFile); - categories[dir] = { displayName: metaData.name }; - const files = readdirSync(resolve(dirPath, dir)); - files.forEach((file) => { - if (file === '_meta.json') return; - if (file.endsWith('.test.js')) return; - const stat = statSync(resolve(dirPath, dir, file)); - if (stat.isFile() && file.endsWith('.js')) { - const fileName = basename(file, '.js'); - const filePath = resolve(dirPath, dir, file); - libNames.push(`yd_${dir}_${fileName}`); - fileData.push( - // - `export { default as yd_${dir}_${fileName} } from './${dirPath}/${dir}/${file}';\r\n` - ); - // 判断是否有相关标签 - const fileData2 = readFileSync(filePath, { encoding: 'utf8' }); - if (!fileData2.includes('@author')) { - console.log(`${filePath} 文件缺少 [作者]`); + // 自动生成导出和单文件 + readdirSync(dirPath).forEach((dir) => { + dirNames.push(dir); + const metaFile = resolve(dirPath, dir, '_meta.json'); + const metaData = readJsonSync(metaFile); + categories[dir] = { displayName: metaData.name }; + const files = readdirSync(resolve(dirPath, dir)); + files.forEach((file) => { + if (file === '_meta.json') return; + if (file.endsWith('.test.js')) return; + const stat = statSync(resolve(dirPath, dir, file)); + if (stat.isFile() && file.endsWith('.js')) { + const fileName = basename(file, '.js'); + const filePath = resolve(dirPath, dir, file); + // libNames.push(`yd_${dir}_${fileName}`); + fileData.push( + // + `export { default as yd_${dir}_${fileName} } from './${dirPath}/${dir}/${file}';\r\n` + ); + // 判断是否有相关标签 + const fileData2 = readFileSync(filePath, { encoding: 'utf8' }); + if (!fileData2.includes('@author')) { + console.log(`${filePath} 文件缺少 [作者]`); + } + if (!fileData2.includes('@category')) { + console.log(`${filePath} 文件缺少 [分类]`); + } + if (!fileData2.includes('@alias')) { + console.log(`${filePath} 文件缺少 [别名]`); + } + } else { + console.log(`${dir}/${file}不是一个函数文件`); } - if (!fileData2.includes('@category')) { - console.log(`${filePath} 文件缺少 [分类]`); - } - if (!fileData2.includes('@alias')) { - console.log(`${filePath} 文件缺少 [别名]`); - } - } else { - console.log(`${dir}/${file}不是一个函数文件`); - } + }); }); -}); -writeFileSync(`./${dirPath}.js`, fileData.join('')); -writeFileSync(`./${dirPath}Names.js`, `export const ${dirPath}Names = ${JSON.stringify(libNames)};`); -console.log(`${dirPath} 数据生成完毕`); + writeFileSync(`./${dirPath}.js`, fileData.join('')); + // writeFileSync(`./${dirPath}Names.js`, `export const ${dirPath}Names = ${JSON.stringify(libNames)};`); + console.log(`${dirPath} 数据生成完毕`); +}); writeFileSync('./categories.json', JSON.stringify(categories)); diff --git a/libBrowser/url/_meta.json b/libBrowser/url/_meta.json new file mode 100644 index 0000000..91d8c8f --- /dev/null +++ b/libBrowser/url/_meta.json @@ -0,0 +1,4 @@ +{ + "name": "url", + "describe": "链接解析、验证等url相关的处理函数" +} diff --git a/lib/url/getQueryParams.js b/libBrowser/url/getQueryParams.js similarity index 100% rename from lib/url/getQueryParams.js rename to libBrowser/url/getQueryParams.js diff --git a/lib/url/getScriptTagSrc.js b/libBrowser/url/getScriptTagSrc.js similarity index 100% rename from lib/url/getScriptTagSrc.js rename to libBrowser/url/getScriptTagSrc.js diff --git a/lib/url/getScriptTagSrc.test.js b/libBrowser/url/getScriptTagSrc.test.js similarity index 100% rename from lib/url/getScriptTagSrc.test.js rename to libBrowser/url/getScriptTagSrc.test.js diff --git a/libNode/crypto/_meta.json b/libNode/crypto/_meta.json new file mode 100644 index 0000000..bc1b63a --- /dev/null +++ b/libNode/crypto/_meta.json @@ -0,0 +1,4 @@ +{ + "name": "加密解密", + "describe": "md5、base64、sha1等加密和解密函数" +} diff --git a/lib/crypto/hmacMd5_node.js b/libNode/crypto/hmacMd5.js similarity index 100% rename from lib/crypto/hmacMd5_node.js rename to libNode/crypto/hmacMd5.js diff --git a/lib/crypto/md5_node.js b/libNode/crypto/md5.js similarity index 100% rename from lib/crypto/md5_node.js rename to libNode/crypto/md5.js diff --git a/lib/crypto/nanoid_node.js b/libNode/crypto/nanoid.js similarity index 100% rename from lib/crypto/nanoid_node.js rename to libNode/crypto/nanoid.js diff --git a/libNode/number/_meta.json b/libNode/number/_meta.json new file mode 100644 index 0000000..4e57764 --- /dev/null +++ b/libNode/number/_meta.json @@ -0,0 +1,4 @@ +{ + "name": "数字", + "describe": "数字解析、转化、随机、验证等工具函数" +} diff --git a/lib/number/incrTimeID_node.js b/libNode/number/incrTimeID.js similarity index 100% rename from lib/number/incrTimeID_node.js rename to libNode/number/incrTimeID.js diff --git a/package.json b/package.json index ad32803..5e9a4ba 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "yidash", "type": "module", - "version": "1.11.0", + "version": "1.12.1", "private": false, "license": "MIT", "description": "yidash(易大师)一万个JavaScript实用方法库", @@ -23,52 +23,40 @@ ], "exports": { ".": "./lib.js", - "./libNames": "./libNames.js" + "./node": "./libNode.js", + "./browser": "./libBrowser.js" }, "files": [ "config/", "lib/", + "libNode/", + "libBrowser/", "index.js", "LICENSE", "package.json", "README.md", "lib.js", - "libNames.js" + "libNode.js", + "libBrowser.js" ], "scripts": { "gen": "node generate.js", - "docs": "del-cli docs & jsdoc -c jsdoc.json", - "test": "vitest", - "test-ui": "vitest --ui", - "lint": "eslint ./lib", - "lint:fix": "eslint ./lib --fix", - "format": "prettier --write .", - "inspect": "eslint --inspect-config" + "docs": "del-cli docs & jsdoc -c jsdoc.json" }, "dependencies": { "date-fns": "^4.1.0", "es-toolkit": "^1.27.0" }, "devDependencies": { - "@eslint/config-inspector": "^0.5.6", - "@eslint/js": "^9.15.0", - "@vitest/ui": "^2.1.6", "colorette": "^2.0.20", "del-cli": "^6.0.0", "docdash-extended-chensuiyi": "^1.1.1", - "eslint": "^9.15.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-jsdoc": "^50.6.0", - "eslint-plugin-prettier": "^5.2.1", - "eslint-plugin-regexp": "^2.7.0", "fs-extra": "^11.2.0", - "globals": "^15.12.0", "jsdoc": "^4.0.4", "lint-staged": "^15.2.10", "log-symbols": "^7.0.0", "prettier": "^3.4.1", - "simple-git-hooks": "^2.11.1", - "vitest": "^2.1.6" + "simple-git-hooks": "^2.11.1" }, "simple-git-hooks": { "pre-commit": "pnpm exec lint-staged" diff --git a/vitest.config.mjs b/vitest.config.mjs deleted file mode 100644 index 9ef0ace..0000000 --- a/vitest.config.mjs +++ /dev/null @@ -1,9 +0,0 @@ -import { defineConfig } from 'vitest/config'; - -export default defineConfig({ - test: { - globals: true, - // include: ['**/lib/*.test.js'], - dir: './' - } -});