From 1f43f2a99b143a321da236a723c05dafeba00960 Mon Sep 17 00:00:00 2001 From: zhujingjing Date: Fri, 10 Nov 2023 16:35:59 +0800 Subject: [PATCH] test --- index.html | 13 ------------- index.ts | 3 --- lib/commons/index.d.ts | 2 ++ lib/commons/str-utils.d.ts | 9 +++++++++ lib/index.d.ts | 2 ++ lib/index.es.js | 16 ++++++++++++++++ lib/index.es.js.map | 1 + package.json | 10 +++++----- public/vite.svg | 1 - src/counter.ts | 9 --------- src/index.ts | 3 +++ src/main.ts | 24 ------------------------ tsconfig.build.json | 12 ++++++++++++ tsconfig.json | 4 ++-- vite.config.js | 29 +++++++++++++++++++++++++++++ 15 files changed, 81 insertions(+), 57 deletions(-) delete mode 100644 index.html delete mode 100644 index.ts create mode 100644 lib/commons/index.d.ts create mode 100644 lib/commons/str-utils.d.ts create mode 100644 lib/index.d.ts create mode 100644 lib/index.es.js create mode 100644 lib/index.es.js.map delete mode 100644 public/vite.svg delete mode 100644 src/counter.ts create mode 100644 src/index.ts delete mode 100644 src/main.ts create mode 100644 tsconfig.build.json create mode 100644 vite.config.js diff --git a/index.html b/index.html deleted file mode 100644 index 44a9335..0000000 --- a/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - Vite + TS - - -
- - - diff --git a/index.ts b/index.ts deleted file mode 100644 index 1e608b6..0000000 --- a/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { stringTokenizer } from "./src/commons"; - -export { stringTokenizer } \ No newline at end of file diff --git a/lib/commons/index.d.ts b/lib/commons/index.d.ts new file mode 100644 index 0000000..a3a16ba --- /dev/null +++ b/lib/commons/index.d.ts @@ -0,0 +1,2 @@ +import { stringTokenizer } from "./str-utils"; +export { stringTokenizer }; diff --git a/lib/commons/str-utils.d.ts b/lib/commons/str-utils.d.ts new file mode 100644 index 0000000..7e5eb4d --- /dev/null +++ b/lib/commons/str-utils.d.ts @@ -0,0 +1,9 @@ +/** + * 生成给定函数体的函数注释。 + * + * @param {RegExp} regExp - 用于匹配的正则表达式。 + * @param {(text: string, match: boolean) => T} matchHandler - 处理匹配到的文本的函数。 + * @param {(text: string, match: boolean) => T} [textHandler] - 处理未匹配到的文本的函数。 + * @return {(str: string) => T[]} - 分词器函数。 + */ +export declare function stringTokenizer(regExp: RegExp, matchHandler: (text: string, match: boolean) => T, textHandler?: (text: string, match: boolean) => T): (str: string) => T[]; diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..4280404 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,2 @@ +import { stringTokenizer } from "./commons"; +export { stringTokenizer }; diff --git a/lib/index.es.js b/lib/index.es.js new file mode 100644 index 0000000..437d873 --- /dev/null +++ b/lib/index.es.js @@ -0,0 +1,16 @@ +function r(u, i, o) { + const h = i, s = o || i; + return function(e) { + const n = [], l = e.matchAll(u); + let t = 0; + for (const c of l) { + const f = e.slice(t, c.index); + f && n.push(s(f, !1)), n.push(h(c[0], !0)), t = c.index + c[0].length; + } + return t < e.length && n.push(s(e.slice(t), !1)), n; + }; +} +export { + r as stringTokenizer +}; +//# sourceMappingURL=index.es.js.map diff --git a/lib/index.es.js.map b/lib/index.es.js.map new file mode 100644 index 0000000..ffd9d90 --- /dev/null +++ b/lib/index.es.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.es.js","sources":["../src/commons/str-utils.ts"],"sourcesContent":["/**\r\n * 生成给定函数体的函数注释。\r\n *\r\n * @param {RegExp} regExp - 用于匹配的正则表达式。\r\n * @param {(text: string, match: boolean) => T} matchHandler - 处理匹配到的文本的函数。\r\n * @param {(text: string, match: boolean) => T} [textHandler] - 处理未匹配到的文本的函数。\r\n * @return {(str: string) => T[]} - 分词器函数。\r\n */\r\n export function stringTokenizer(\r\n regExp: RegExp,\r\n matchHandler: (text: string, match: boolean) => T,\r\n textHandler?: (text: string, match: boolean) => T\r\n ): (str: string) => T[] {\r\n\r\n const ifMatch = matchHandler;\r\n const ifText = textHandler?textHandler: matchHandler;\r\n\r\n return function (str: string) {\r\n const result: T[] = [];\r\n const matches = str.matchAll(regExp);\r\n let index = 0;\r\n for (const match of matches) {\r\n const before = str.slice(index, match.index);\r\n if (before) {\r\n result.push(ifText(before, false));\r\n }\r\n result.push(ifMatch(match[0], true));\r\n index = match.index! + match[0].length;\r\n }\r\n if (index < str.length) {\r\n result.push(ifText(str.slice(index), false));\r\n }\r\n return result;\r\n };\r\n }"],"names":["stringTokenizer","regExp","matchHandler","textHandler","ifMatch","ifText","str","result","matches","index","match","before"],"mappings":"AAQkB,SAAAA,EACdC,GACAC,GACAC,GACsB;AAEtB,QAAMC,IAAUF,GACVG,IAASF,KAAyBD;AAExC,SAAO,SAAUI,GAAa;AAC5B,UAAMC,IAAc,CAAA,GACdC,IAAUF,EAAI,SAASL,CAAM;AACnC,QAAIQ,IAAQ;AACZ,eAAWC,KAASF,GAAS;AAC3B,YAAMG,IAASL,EAAI,MAAMG,GAAOC,EAAM,KAAK;AAC3C,MAAIC,KACFJ,EAAO,KAAKF,EAAOM,GAAQ,EAAK,CAAC,GAEnCJ,EAAO,KAAKH,EAAQM,EAAM,CAAC,GAAG,EAAI,CAAC,GACnCD,IAAQC,EAAM,QAASA,EAAM,CAAC,EAAE;AAAA,IAClC;AACI,WAAAD,IAAQH,EAAI,UACdC,EAAO,KAAKF,EAAOC,EAAI,MAAMG,CAAK,GAAG,EAAK,CAAC,GAEtCF;AAAA,EAAA;AAEX;"} \ No newline at end of file diff --git a/package.json b/package.json index df1042c..c0e68be 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", - "build": "tsc && vite build", - "preview": "vite preview" + "build": "vite build && tsc -p tsconfig.build.json" }, "devDependencies": { "typescript": "^5.0.2", "vite": "^4.4.5" - } -} + }, + "module": "./lib/index.es.js", + "types": "./lib/index.d.ts" +} \ No newline at end of file diff --git a/public/vite.svg b/public/vite.svg deleted file mode 100644 index e7b8dfb..0000000 --- a/public/vite.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/counter.ts b/src/counter.ts deleted file mode 100644 index 09e5afd..0000000 --- a/src/counter.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function setupCounter(element: HTMLButtonElement) { - let counter = 0 - const setCounter = (count: number) => { - counter = count - element.innerHTML = `count is ${counter}` - } - element.addEventListener('click', () => setCounter(counter + 1)) - setCounter(0) -} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..f87766e --- /dev/null +++ b/src/index.ts @@ -0,0 +1,3 @@ +import { stringTokenizer } from "./commons"; + +export { stringTokenizer } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts deleted file mode 100644 index 791547b..0000000 --- a/src/main.ts +++ /dev/null @@ -1,24 +0,0 @@ -import './style.css' -import typescriptLogo from './typescript.svg' -import viteLogo from '/vite.svg' -import { setupCounter } from './counter.ts' - -document.querySelector('#app')!.innerHTML = ` -
- - - - - - -

Vite + TypeScript

-
- -
-

- Click on the Vite and TypeScript logos to learn more -

-
-` - -setupCounter(document.querySelector('#counter')!) diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..ba1aa5d --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", // 拓展 tsconfig.json 的配置 + "compilerOptions": { + "noEmit": false, // 允许生成文件 + "declaration": true, // 需要设置为 true 来支持类型 + "emitDeclarationOnly": true, // 只生成类型文件 + "declarationDir": "lib" // 类型文件的导出目录 + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 8146047..ca2fa98 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,12 +12,12 @@ "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, - + /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["src", "index.ts", "index.ts"] + "include": ["src"] } diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..eff3f40 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,29 @@ +import { defineConfig } from 'vite' + + +// https://vitejs.dev/config/ +export default defineConfig({ + + // 打包配置 + build: { + lib: { + entry: 'src/index.ts', // 设置入口文件 + name: 'ez-common-ts', // 起个名字,安装、引入用 + formats: ['es'], + fileName: (format) => `index.${format}.js` // 打包后的文件名 + }, + sourcemap: true, // 输出.map文件 + rollupOptions: { + // 确保外部化处理那些你不想打包进库的依赖 + //external: ['vue', 'ant-design-vue'], + /*output: { + // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量 + globals: { + vue: 'Vue', + 'ant-design-vue': 'ant-design-vue' + } + } */ + }, + outDir: 'lib' // 默认为 dist + }, +}) \ No newline at end of file