$ cnpm install prop-ini
Read, Write, Encode, Decode & Manage INI/Property files with ease.
npm install prop-ini
1] Require the module in your code
var PropINI = require("prop-ini");
2] Create new instance for PropINI
var piTheOne = PropIni.createInstance();
3] Decode/Read data
var iniData = piTheOne.decode(<config>);
<config> is an object with following props
config.data - Pass the INI/Properties format data directly as a stringconfig.file - Tell the function to get the data from this fileconfig.charset - Tell function to read file by this encodingconfig.lineSeparator - Tell function to split lines based on this charThe returned iniData is an object with following props
iniData.sections - Object containing sections as top-level nodes and properties of appropriate sections as child nodes for them. _global is a special section where properties without any section are availableiniData.sectionOrder - Array of section names in exact order matching the parsed data. _global will be the first entryOn successfull decode the parsed values will be stored with the PropINI instance as properties. You may access them using piTheOne.sections and piThOne.sectionOrder. Handle with care !
4] Encode/Write data
var iniString = piTheOne.encode(<config>);
<config> is an object with following props
config.sortSections - Sort section names using String.prototype.localeCompareconfig.sortKeys - Sort properties/keys under each section with localeCompareconfig.file - Tell function write the encoded data to this fileconfig.charset - Tell function to write file with this encodingconfig.lineSeparator - Tell function to join lines based on this charThe returned iniString is a string type variable containg INI/Property file format data
1] Get section names as an Array
var sections = piTheOne.getSections();
sections is an Array containing all sections in the parsed instance data_global is excluded2] Get anything you want !
var data = piTheOne.getData(<section>, <key>);
section is the name of the section. In absense of key whole section's object with child properties will be returnedkey is the name of the property under some section. In absense of section, _global section will be used. String value of a key will be returnedsection & key, whole data will be returned as an object with sections, sectionOrder as properties3] Set anything you want !
var success = piTheOne.addData(<value>, <section>, <key>);
section is the name of the section. value should be given as an object in this casekey is the name of the property under some section. In absense of section, _global section will be used. value should be of String type in this casesection & key, you can set the whole data for the instance. An object with sections, sectionOrder as properties should be given for value. sections property should have _global child property.4] Remove anything you want !
var success = piTheOne.removeData(<section>, <key>);
section is the name of the section. In absense of key whole section will be removed.key is the name of the property under some section. In absense of section, _global section will be used.section & key, whole instance data will be reset to empty state.piTheOne.sections should always be an objectpiTheOne.sectionOrder should always be an array and should be in sync with piTheOne.sections datapiTheOne.sections should always have a child object _globalCopyright 2013 - present © cnpmjs.org | Home |