Socket
Socket
Sign inDemoInstall

ini

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

LICENSE

7

ini.js

@@ -26,3 +26,7 @@

children.forEach(function (k, _, __) {
out += encode(obj[k], (section ? section + "." : "") + k)
var child = encode(obj[k], (section ? section + "." : "") + k)
if (out.length && child.length) {
out += "\n"
}
out += child
})

@@ -86,2 +90,3 @@

|| val.match(/[\r\n]/)
|| val.match(/^\[/)
|| (val.length > 1

@@ -88,0 +93,0 @@ && val.charAt(0) === "\""

2

package.json

@@ -5,3 +5,3 @@ {

"description": "An ini encoder/decoder for node",
"version": "1.0.1",
"version": "1.0.2",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -5,1 +5,68 @@ An ini format parser and serializer for node.

are saved on the object directly.
## Usage
Consider an ini-file `config.ini` that looks like this:
; this comment is being ignored
scope = global
[database]
user = dbuser
password = dbpassword
database = use_this_database
[paths.default]
datadir = /var/lib/data
You can read, manipulate and write the ini-file like so:
var fs = require('fs')
, ini = require('ini')
var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
config.scope = 'local'
config.database.database = 'use_another_database'
config.paths.default.tmpdir = '/tmp'
delete config.paths.default.datadir
fs.writeFileSync('./config_modified.ini', ini.stringify(config, 'section'))
This will result in a file called `config_modified.ini` being written to the filesystem with the following content:
[section]
scope = local
[section.database]
user = dbuser
password = dbpassword
database = use_another_database
[section.paths.default]
tmpdir = /tmp
## API
### decode(inistring)
Decode the ini-style formatted `inistring` into a nested object.
### parse(inistring)
Alias for `decode(inistring)`
### encode(object, [section])
Encode the object `object` into an ini-style formatted string. If the optional parameter `section` is given, then all top-level properties of the object are put into this section and the `section`-string is prepended to all sub-sections, see the usage example above.
### stringify(object, [section])
Alias for `encode(object, [section])`
### safe(val)
Escapes the string `val` such that it is safe to be used as a key or value in an ini-file. Basically escapes quotes. For example
ini.safe('"unsafe string"')
would result in
"\"unsafe string\""
### unsafe(val)
Unescapes the string `val`

@@ -12,9 +12,11 @@ var i = require("../")

+ '" xa n p " = "\\"\\r\\nyoyoyo\\r\\r\\n"\n'
+ '"[disturbing]" = hey you never know\n'
+ '\n'
+ '[a]\n'
+ 'av = a val\n'
+ 'e = { o: p, a: '
+ '{ av: a val, b: { c: { e: "this value" '
+ '{ av: a val, b: { c: { e: "this [value]" '
+ '} } } }\nj = "\\"{ o: \\"p\\", a: { av:'
+ ' \\"a val\\", b: { c: { e: \\"this value'
+ '\\" } } } }\\""\n[a.b.c]\ne = 1\nj = 2\n'
+ ' \\"a val\\", b: { c: { e: \\"this [value]'
+ '\\" } } } }\\""\n"[]" = a square?\n\n[a.b.c]\ne = 1\nj = 2\n'
, expectD =

@@ -24,6 +26,8 @@ { o: 'p',

" xa n p ":'"\r\nyoyoyo\r\r\n',
'[disturbing]': 'hey you never know',
a:
{ av: 'a val',
e: '{ o: p, a: { av: a val, b: { c: { e: "this value" } } } }',
j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this value" } } } }"',
e: '{ o: p, a: { av: a val, b: { c: { e: "this [value]" } } } }',
j: '"{ o: "p", a: { av: "a val", b: { c: { e: "this [value]" } } } }"',
"[]": "a square?",
b: { c: { e: '1', j: '2' } } }

@@ -33,3 +37,3 @@ }

test("decode from file", function (t) {
d = i.decode(data)
var d = i.decode(data)
t.deepEqual(d, expectD)

@@ -40,5 +44,11 @@ t.end()

test("encode from data", function (t) {
e = i.encode(expectD)
var e = i.encode(expectD)
t.deepEqual(e, expectE)
var obj = {log: { type:'file', level: {label:'debug', value:10} } }
e = i.encode(obj)
t.notEqual(e.slice(0, 1), '\n', 'Never a blank first line')
t.notEqual(e.slice(-2), '\n\n', 'Never a blank final line')
t.end()
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc