parse-ini-string
Advanced tools
Comparing version 0.0.7 to 0.1.0
@@ -5,8 +5,8 @@ "use strict"; | ||
var _chai = require("chai"); | ||
var _index = _interopRequireDefault(require("../index")); | ||
var _chai = require("chai"); | ||
describe('Test parse ini', function () { | ||
var testData = "\nfoo=bar\nabc=def\n"; | ||
var testData = "\nfoo=bar\nabc=def\n111=\"222\"\naaa='bbb'\n"; | ||
it('Test simple', function () { | ||
@@ -16,3 +16,5 @@ var arr = (0, _index["default"])(testData); | ||
foo: 'bar', | ||
abc: 'def' | ||
abc: 'def', | ||
'111': '222', | ||
aaa: 'bbb' | ||
}); | ||
@@ -32,11 +34,2 @@ }); | ||
}); | ||
it('Test multi line', function () { | ||
var uMultiLineText = "\na=\"000\n111\n\"\nb=\"111\n222\n333\n\";\n"; | ||
var arr = (0, _index["default"])(uMultiLineText); | ||
var expected = { | ||
a: '000\n111', | ||
b: '111\n222\n333' | ||
}; | ||
(0, _chai.expect)(arr).to.deep.equal(expected); | ||
}); | ||
}); |
@@ -18,4 +18,4 @@ "use strict"; | ||
var bAndE = s.charAt(0) + '' + s.slice(-1); | ||
var bAndE2 = s.charAt(0) + '' + s.slice(-2); | ||
var bAndE = s.charAt(0) + "" + s.slice(-1); | ||
var bAndE2 = s.charAt(0) + "" + s.slice(-2); | ||
return bAndE === '""' || bAndE === "''" || bAndE2 === '"";' || bAndE2 === "'';"; | ||
@@ -25,3 +25,3 @@ }; | ||
var stripQuote = function stripQuote(s) { | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - (s.slice(-1) === ';' ? 2 : 1)); | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - (s.slice(-1) === ";" ? 2 : 1)); | ||
}; | ||
@@ -41,4 +41,4 @@ | ||
var lines = s.split(linesReg); | ||
var value = ''; | ||
var key = ''; | ||
var value = ""; | ||
var key = ""; | ||
var p = {}; | ||
@@ -56,3 +56,3 @@ lines.forEach(function (line) { | ||
if (!match) { | ||
console.error('Ini Parse Fail: ' + line); | ||
console.error("Ini Parse Fail: " + line); | ||
return; | ||
@@ -62,5 +62,5 @@ } | ||
key = match[2]; | ||
value = match[3] ? match[4] || '' : ''; | ||
value = match[3] ? match[4] || "" : ""; | ||
if (key.length > 2 && key.slice(-2) === '[]') { | ||
if (key.length > 2 && key.slice(-2) === "[]") { | ||
key = key.substring(0, key.length - 2); | ||
@@ -81,4 +81,10 @@ | ||
if (lineTrim.slice(-1) === '"' || lineTrim.slice(-2) === '";') { | ||
isEnd = true; | ||
if (isMultiLine(value)) { | ||
if (lineTrim === '"' || lineTrim === '";') { | ||
isEnd = true; | ||
} | ||
} else { | ||
if (lineTrim.slice(-1) === '"' || lineTrim.slice(-2) === '";') { | ||
isEnd = true; | ||
} | ||
} | ||
@@ -98,5 +104,5 @@ | ||
switch (value.toLowerCase()) { | ||
case 'true': | ||
case 'false': | ||
case 'null': | ||
case "true": | ||
case "false": | ||
case "null": | ||
value = JSON.parse(value.toLowerCase()); | ||
@@ -117,4 +123,4 @@ break; | ||
key = ''; | ||
value = ''; | ||
key = ""; | ||
value = ""; | ||
} | ||
@@ -121,0 +127,0 @@ }); |
@@ -0,5 +1,5 @@ | ||
import { expect } from 'chai'; | ||
import parse from '../index'; | ||
import { expect } from 'chai'; | ||
describe('Test parse ini', function () { | ||
var testData = "\nfoo=bar\nabc=def\n"; | ||
var testData = "\nfoo=bar\nabc=def\n111=\"222\"\naaa='bbb'\n"; | ||
it('Test simple', function () { | ||
@@ -9,3 +9,5 @@ var arr = parse(testData); | ||
foo: 'bar', | ||
abc: 'def' | ||
abc: 'def', | ||
'111': '222', | ||
aaa: 'bbb' | ||
}); | ||
@@ -25,11 +27,2 @@ }); | ||
}); | ||
it('Test multi line', function () { | ||
var uMultiLineText = "\na=\"000\n111\n\"\nb=\"111\n222\n333\n\";\n"; | ||
var arr = parse(uMultiLineText); | ||
var expected = { | ||
a: '000\n111', | ||
b: '111\n222\n333' | ||
}; | ||
expect(arr).to.deep.equal(expected); | ||
}); | ||
}); |
@@ -12,4 +12,4 @@ var commentReg = /^\s*[;]/; | ||
var bAndE = s.charAt(0) + '' + s.slice(-1); | ||
var bAndE2 = s.charAt(0) + '' + s.slice(-2); | ||
var bAndE = s.charAt(0) + "" + s.slice(-1); | ||
var bAndE2 = s.charAt(0) + "" + s.slice(-2); | ||
return bAndE === '""' || bAndE === "''" || bAndE2 === '"";' || bAndE2 === "'';"; | ||
@@ -19,3 +19,3 @@ }; | ||
var stripQuote = function stripQuote(s) { | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - (s.slice(-1) === ';' ? 2 : 1)); | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - (s.slice(-1) === ";" ? 2 : 1)); | ||
}; | ||
@@ -35,4 +35,4 @@ | ||
var lines = s.split(linesReg); | ||
var value = ''; | ||
var key = ''; | ||
var value = ""; | ||
var key = ""; | ||
var p = {}; | ||
@@ -50,3 +50,3 @@ lines.forEach(function (line) { | ||
if (!match) { | ||
console.error('Ini Parse Fail: ' + line); | ||
console.error("Ini Parse Fail: " + line); | ||
return; | ||
@@ -56,5 +56,5 @@ } | ||
key = match[2]; | ||
value = match[3] ? match[4] || '' : ''; | ||
value = match[3] ? match[4] || "" : ""; | ||
if (key.length > 2 && key.slice(-2) === '[]') { | ||
if (key.length > 2 && key.slice(-2) === "[]") { | ||
key = key.substring(0, key.length - 2); | ||
@@ -75,4 +75,10 @@ | ||
if (lineTrim.slice(-1) === '"' || lineTrim.slice(-2) === '";') { | ||
isEnd = true; | ||
if (isMultiLine(value)) { | ||
if (lineTrim === '"' || lineTrim === '";') { | ||
isEnd = true; | ||
} | ||
} else { | ||
if (lineTrim.slice(-1) === '"' || lineTrim.slice(-2) === '";') { | ||
isEnd = true; | ||
} | ||
} | ||
@@ -92,5 +98,5 @@ | ||
switch (value.toLowerCase()) { | ||
case 'true': | ||
case 'false': | ||
case 'null': | ||
case "true": | ||
case "false": | ||
case "null": | ||
value = JSON.parse(value.toLowerCase()); | ||
@@ -111,4 +117,4 @@ break; | ||
key = ''; | ||
value = ''; | ||
key = ""; | ||
value = ""; | ||
} | ||
@@ -115,0 +121,0 @@ }); |
{ | ||
"name": "parse-ini-string", | ||
"version": "0.0.7", | ||
"version": "0.1.0", | ||
"description": "PHP parse-ini-string like library, support multi line", | ||
@@ -24,3 +24,4 @@ "repository": "react-atomic/react-atomic-organism", | ||
"build:es": "BABEL_ENV=es babel src -d build/es/src --root-mode upward", | ||
"test": "npm run build && mocha 'build/cjs/**/__tests__/*.js'", | ||
"mocha": "mocha 'build/cjs/**/__tests__/*.js'", | ||
"test": "npm run build && npm run mocha", | ||
"prepublishOnly": "npm run test && npm run build" | ||
@@ -27,0 +28,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8702
8
273