From 4ec3ecb69b417bcc137a8df80fc482f45c6a1d89 Mon Sep 17 00:00:00 2001 From: kangkang520 Date: Mon, 12 Nov 2018 23:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B3=A8=E9=87=8A=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.ts | 2 +- test/test.ini | 36 +++++++++++++++++++----------------- test/test.ts | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index d8e7d28..bf182d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ini-decode", - "version": "1.0.3", + "version": "1.0.4", "description": "", "main": "dist/index.js", "types": "typing/index.d.ts", diff --git a/src/index.ts b/src/index.ts index f2eb593..c8f8ec9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,7 @@ function parseBase(_content: string | Buffer) { //此函数用于加入值到结果 (_content + '') //删除注释 - .replace(/[;#][\s\S]*?\r?\n/g, '\n') + .replace(/[;#][\s\S]*?\r?$/gm, '') //按行分割 .split(/\r?\n/) //trim + filter diff --git a/test/test.ini b/test/test.ini index e3c77d9..13c8bff 100644 --- a/test/test.ini +++ b/test/test.ini @@ -1,19 +1,21 @@ -[user.id1] -id = 1 -name = Mimi -gender = female -isAdmin = true +# 数据库配置 +[database] +# 默认数据库 +default = mysql +# 是否打印日志 +logging = false +# 是否自动建表或更新表 +synchronize = true -[user.id2] -id = 2 -name = Mimi -gender = female -isAdmin = true +# mysql数据库配置 +[mysql] +type = mysql +host = 127.0.0.1 +port = 3306 +username = root +password = 123456 +database = shipwin-dev-v2 -[password] -# 注释 -admin = 123 -login = "456" -test[] = 789 -test[] = 789 -test2 = 123,456,"789" +# 可以有其他数据库配置 +# [] +# = \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index fa66e28..f17cb26 100644 --- a/test/test.ts +++ b/test/test.ts @@ -3,4 +3,4 @@ import { decode } from '../src' const content = fs.readFileSync(__dirname + '/test.ini') const res = decode(content) -console.log(res) \ No newline at end of file +console.log(res.json) \ No newline at end of file