parse-ini-string
Advanced tools
Comparing version 0.0.2 to 0.0.3
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
@@ -9,84 +9,80 @@ var commentReg = /^\s*[;]/; | ||
var linesReg = /[\r\n]+/g; | ||
var trimReg = /(^\s+)|\s+$/g; | ||
var stripQuoteReg = /\\"/g; | ||
var isArray = Array.isArray; | ||
var trim = function trim(s) { | ||
return s.replace(trimReg, ''); | ||
}; | ||
var isQuoted = function isQuoted(s) { | ||
if (s.length <= 1) { | ||
return false; | ||
} | ||
return s.charAt(0) === '"' && s.slice(-1) === '"' || s.charAt(0) === "'" && s.slice(-1) === "'"; | ||
if (s.length <= 1) { | ||
return false; | ||
} | ||
var bAndE = s.charAt(0) + '' + s.slice(-1); | ||
return bAndE === '""' || bAndE === "''"; | ||
}; | ||
var stripQuote = function stripQuote(s) { | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - 1); | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - 1); | ||
}; | ||
var isMultiLine = function isMultiLine(s) { | ||
var n = trim(s); | ||
if (isQuoted(n)) { | ||
return false; | ||
} | ||
if (n.charAt(0) === '"') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
var n = s.trim(); | ||
if (isQuoted(n)) { | ||
return false; | ||
} | ||
if (n.charAt(0) === '"') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
var parse = function parse(s) { | ||
var lines = s.split(linesReg); | ||
var value = ''; | ||
var key = ''; | ||
var p = {}; | ||
lines.forEach(function (line) { | ||
var isEnd = false; | ||
if (!line || commentReg.test(line)) { | ||
return; | ||
var lines = s.split(linesReg); | ||
var value = ''; | ||
var key = ''; | ||
var p = {}; | ||
lines.forEach(function (line) { | ||
var isEnd = false; | ||
if (!line || commentReg.test(line)) { | ||
return; | ||
} | ||
if (!key) { | ||
var match = line.match(kvReg); | ||
key = match[2]; | ||
value = match[3] ? match[4] || '' : ''; | ||
if (key.length > 2 && key.slice(-2) === '[]') { | ||
key = key.substring(0, key.length - 2); | ||
if (!p[key]) { | ||
p[key] = []; | ||
} else if (!Array.isArray(p[key])) { | ||
p[key] = [p[key]]; | ||
} | ||
if (!key) { | ||
var match = line.match(kvReg); | ||
key = match[2]; | ||
value = match[3] ? match[4] || '' : ''; | ||
if (key.length > 2 && key.slice(-2) === '[]') { | ||
key = key.substring(0, key.length - 2); | ||
if (!p[key]) { | ||
p[key] = []; | ||
} else if (!Array.isArray(p[key])) { | ||
p[key] = [p[key]]; | ||
} | ||
} | ||
if (!isMultiLine(value)) { | ||
isEnd = true; | ||
} | ||
} else { | ||
if (trim(line).slice(-1) === '"') { | ||
isEnd = true; | ||
} | ||
value += line; | ||
} | ||
if (isEnd) { | ||
if (isQuoted(value)) { | ||
value = stripQuote(value); | ||
} | ||
switch (value) { | ||
case 'true': | ||
case 'false': | ||
case 'null': | ||
value = JSON.parse(value); | ||
} | ||
if (isArray(p[key])) { | ||
p[key].push(value); | ||
} else { | ||
p[key] = value; | ||
} | ||
key = ''; | ||
value = ''; | ||
} | ||
}); | ||
return p; | ||
} | ||
if (!isMultiLine(value)) { | ||
isEnd = true; | ||
} | ||
} else { | ||
if (line.trim().slice(-1) === '"') { | ||
isEnd = true; | ||
} | ||
value += line; | ||
} | ||
if (isEnd) { | ||
if (isQuoted(value)) { | ||
value = stripQuote(value); | ||
} | ||
switch (value) { | ||
case 'true': | ||
case 'false': | ||
case 'null': | ||
value = JSON.parse(value); | ||
} | ||
if (isArray(p[key])) { | ||
p[key].push(value); | ||
} else { | ||
p[key] = value; | ||
} | ||
key = ''; | ||
value = ''; | ||
} | ||
}); | ||
return p; | ||
}; | ||
@@ -93,0 +89,0 @@ |
@@ -1,90 +0,84 @@ | ||
'use strict'; | ||
var commentReg = /^\s*[;]/; | ||
var kvReg = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i; | ||
var linesReg = /[\r\n]+/g; | ||
var trimReg = /(^\s+)|\s+$/g; | ||
var stripQuoteReg = /\\"/g; | ||
var isArray = Array.isArray; | ||
var trim = function trim(s) { | ||
return s.replace(trimReg, ''); | ||
}; | ||
var isQuoted = function isQuoted(s) { | ||
if (s.length <= 1) { | ||
return false; | ||
} | ||
return s.charAt(0) === '"' && s.slice(-1) === '"' || s.charAt(0) === "'" && s.slice(-1) === "'"; | ||
if (s.length <= 1) { | ||
return false; | ||
} | ||
var bAndE = s.charAt(0) + '' + s.slice(-1); | ||
return bAndE === '""' || bAndE === "''"; | ||
}; | ||
var stripQuote = function stripQuote(s) { | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - 1); | ||
return s.replace(stripQuoteReg, '"').substring(1, s.length - 1); | ||
}; | ||
var isMultiLine = function isMultiLine(s) { | ||
var n = trim(s); | ||
if (isQuoted(n)) { | ||
return false; | ||
} | ||
if (n.charAt(0) === '"') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
var n = s.trim(); | ||
if (isQuoted(n)) { | ||
return false; | ||
} | ||
if (n.charAt(0) === '"') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
var parse = function parse(s) { | ||
var lines = s.split(linesReg); | ||
var value = ''; | ||
var key = ''; | ||
var p = {}; | ||
lines.forEach(function (line) { | ||
var isEnd = false; | ||
if (!line || commentReg.test(line)) { | ||
return; | ||
var lines = s.split(linesReg); | ||
var value = ''; | ||
var key = ''; | ||
var p = {}; | ||
lines.forEach(function (line) { | ||
var isEnd = false; | ||
if (!line || commentReg.test(line)) { | ||
return; | ||
} | ||
if (!key) { | ||
var match = line.match(kvReg); | ||
key = match[2]; | ||
value = match[3] ? match[4] || '' : ''; | ||
if (key.length > 2 && key.slice(-2) === '[]') { | ||
key = key.substring(0, key.length - 2); | ||
if (!p[key]) { | ||
p[key] = []; | ||
} else if (!Array.isArray(p[key])) { | ||
p[key] = [p[key]]; | ||
} | ||
if (!key) { | ||
var match = line.match(kvReg); | ||
key = match[2]; | ||
value = match[3] ? match[4] || '' : ''; | ||
if (key.length > 2 && key.slice(-2) === '[]') { | ||
key = key.substring(0, key.length - 2); | ||
if (!p[key]) { | ||
p[key] = []; | ||
} else if (!Array.isArray(p[key])) { | ||
p[key] = [p[key]]; | ||
} | ||
} | ||
if (!isMultiLine(value)) { | ||
isEnd = true; | ||
} | ||
} else { | ||
if (trim(line).slice(-1) === '"') { | ||
isEnd = true; | ||
} | ||
value += line; | ||
} | ||
if (isEnd) { | ||
if (isQuoted(value)) { | ||
value = stripQuote(value); | ||
} | ||
switch (value) { | ||
case 'true': | ||
case 'false': | ||
case 'null': | ||
value = JSON.parse(value); | ||
} | ||
if (isArray(p[key])) { | ||
p[key].push(value); | ||
} else { | ||
p[key] = value; | ||
} | ||
key = ''; | ||
value = ''; | ||
} | ||
}); | ||
return p; | ||
} | ||
if (!isMultiLine(value)) { | ||
isEnd = true; | ||
} | ||
} else { | ||
if (line.trim().slice(-1) === '"') { | ||
isEnd = true; | ||
} | ||
value += line; | ||
} | ||
if (isEnd) { | ||
if (isQuoted(value)) { | ||
value = stripQuote(value); | ||
} | ||
switch (value) { | ||
case 'true': | ||
case 'false': | ||
case 'null': | ||
value = JSON.parse(value); | ||
} | ||
if (isArray(p[key])) { | ||
p[key].push(value); | ||
} else { | ||
p[key] = value; | ||
} | ||
key = ''; | ||
value = ''; | ||
} | ||
}); | ||
return p; | ||
}; | ||
export default parse; |
{ | ||
"name": "parse-ini-string", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "PHP like parse-ini-string, support multi line", | ||
@@ -5,0 +5,0 @@ "repository": "react-atomic/react-atomic-organism", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
5049
161