From bdca240465ab765f7fdc181d7bc41dc621b30e0d Mon Sep 17 00:00:00 2001 From: bonn Date: Sat, 9 Oct 2021 10:06:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3demo=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E4=B8=8A=E7=9A=84=E4=B8=80=E4=B8=AA=E9=94=99=E8=AF=AF=20(#14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改demo程序的一个错误 * 修正demo上一个错误 --- TypeScript/README.md | 13 +++++++------ TypeScript/test/test1.ts | 9 +++++++++ TypeScript/test/{test.ts => test2.ts} | 0 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 TypeScript/test/test1.ts rename TypeScript/test/{test.ts => test2.ts} (100%) diff --git a/TypeScript/README.md b/TypeScript/README.md index 1509999..00e643e 100644 --- a/TypeScript/README.md +++ b/TypeScript/README.md @@ -10,9 +10,7 @@ 执行测试代码 ```bash -ts-node test/test.ts - -NODE_ENV=development REDIS_HOST=127.0.0.1 +ts-node test/test1.ts ``` @@ -20,11 +18,14 @@ NODE_ENV=development REDIS_HOST=127.0.0.1 ## 使用 ```js -import { Genid } from '../index' +import { snowflakeIdv1 } from '../snowflakeIdv1' + +const WorkerId = process.env.WorkerId == undefined ? 1 : process.env.WorkerId +const Method = process.env.Method == undefined ? 1 : process.env.Method -let gen = new Genid({ WorkerId: 1 }) -let id1 = gen.NextId() +let gen1 = new snowflakeIdv1({ WorkerId: WorkerId, Method: Method }) +let id1 = gen1.NextId() console.log(id1, id1.toString().length) ``` diff --git a/TypeScript/test/test1.ts b/TypeScript/test/test1.ts new file mode 100644 index 0000000..1957567 --- /dev/null +++ b/TypeScript/test/test1.ts @@ -0,0 +1,9 @@ +import { snowflakeIdv1 } from '../snowflakeIdv1' + +const WorkerId = process.env.WorkerId == undefined ? 1 : process.env.WorkerId + +const Method = process.env.Method == undefined ? 1 : process.env.Method + +let gen1 = new snowflakeIdv1({ WorkerId: WorkerId, Method: Method }) +let id1 = gen1.NextId() +console.log(id1, id1.toString().length) \ No newline at end of file diff --git a/TypeScript/test/test.ts b/TypeScript/test/test2.ts similarity index 100% rename from TypeScript/test/test.ts rename to TypeScript/test/test2.ts