Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-ini-string

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-ini-string - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

134

build/cjs/src/index.js
'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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc