Permalink
Browse files

v1.2.0

  • Loading branch information...
1 parent 6f03803 commit 5639dcaf2dc59a3b2f35de2c14c96183fc7dcc80 Gabriel Llamas committed Feb 7, 2014
Showing with 279 additions and 171 deletions.
  1. +88 −82 CHANGES
  2. +38 −22 README.md
  3. +7 −6 examples/namespaces/namespaces
  4. +5 −1 examples/namespaces/namespaces.js
  5. +0 −3 lib/parse.js
  6. +97 −52 lib/read.js
  7. +1 −1 package.json
  8. +2 −2 test/namespaces-sections
  9. +35 −2 test/parse.js
  10. +6 −0 test/variables-sections-namespaces
View
170 CHANGES
@@ -1,137 +1,143 @@
+v1.2.0 (07 Feb 2014)
+ The sections now can contain a namespace chain, that is, dot-separated
+ sections can be split up like dot-separated properties.
+ Fixed variable expansion when the "namespace" option is enabled.
+ Minor improvements.
+
v1.1.3 (07 Dec 2013)
- When a namespace chain is invalid it now returns an error.
+ When a namespace chain is invalid it now returns an error.
v1.1.2 (22 Oct 2013)
- Bugfix stringifying characters when "unicode" was true (improved ISO 8859-1
- compatibility).
+ Bugfix stringifying characters when "unicode" was true (improved ISO 8859-1
+ compatibility).
v1.1.1 (14 Oct 2013)
- Bugfix when "parse()" was called with only 1 parameter.
+ Bugfix when "parse()" was called with only 1 parameter.
v1.1.0 (12 Oct 2013)
- Removed "json" parsing option (improved parsing speed).
- Removed "Stringifier.from()".
- Removed optional parameter from "stringifier()".
- Renamed "stringifier()" to "createStringifier()".
+ Removed "json" parsing option (improved parsing speed).
+ Removed "Stringifier.from()".
+ Removed optional parameter from "stringifier()".
+ Renamed "stringifier()" to "createStringifier()".
v1.0.4 (07 Sep 2013)
- When "namespaces" are in use the objects are merged correctly.
- When "path" is used the callback is called correctly.
+ When "namespaces" are in use the objects are merged correctly.
+ When "path" is used the callback is called correctly.
v1.0.3 (16 Aug 2013)
- The paths from the imported files are relative to the current file.
+ The paths from the imported files are relative to the current file.
v1.0.2 (16 Aug 2013)
- Minor bugfixes with sections that don't end with "]".
+ Minor bugfixes with sections that don't end with "]".
v1.0.1 (11 Aug 2013)
- Some bugfixes including files.
+ Some bugfixes including files.
v1.0.0 (08 Aug 2013)
- Complete refactor from scratch.
- Improved reading speed by ~45%. This new version iterates the data only once
- while the previous version was a direct port from the Java source code and
- was iterating four times over the same data.
- Improved writing speed by ~77%.
- All the dependencies have been removed.
- If the sections are enabled the properties should be stringified using a
- Stringifier instead of giving a raw object.
- "load()" and "store" have been removed and "parse()" and "stringify()" can
- read and write from/to files with the "path" option.
- Added "json" option to "parse()". When it is enabled stringified json arrays
- and objects are parsed into javascript arrays and objects.
- Added "namespaces" option to "parse()". When it is enabled the dots in the
- keys will be interpreted as namespaces.
- Added "vars" option to "parse()". When the variables are enabled and a
- variable does not exist it first looks into the "vars" object before
- throwing an error. It can be used to pass environment variables.
- Added "strict" option to "parse()". When it is enabled the parser will only
- consider as coments and separators the tokens included in the "comments"
- and "separators" options.
- Added "include" option to "parse()". The "include" key can be used to import
- other files.
- Removed "bufferSize" and "encoding" options. Files are read using a 16KB
- buffer size and utf8 encoding.
- Removed the "pretty" option from "stringify()". The required code to
- accomplish the column limit is too complex and the feature is rarely used.
- This option contains bugs in the previous versions. The overall stringify
- speed is faster.
- The stringify replacer must be a function. Cannot be an array like in previous
- versions.
- Some bugfixes with escaped backslashes.
- Some bugfixes with whitespace values.
- Some bugfixes with sections.
- Some bugfixes with "stringify()".
+ Complete refactor from scratch.
+ Improved reading speed by ~45%. This new version iterates the data only once
+ while the previous version was a direct port from the Java source code and
+ was iterating four times over the same data.
+ Improved writing speed by ~77%.
+ All the dependencies have been removed.
+ If the sections are enabled the properties should be stringified using a
+ Stringifier instead of giving a raw object.
+ "load()" and "store" have been removed and "parse()" and "stringify()" can
+ read and write from/to files with the "path" option.
+ Added "json" option to "parse()". When it is enabled stringified json arrays
+ and objects are parsed into javascript arrays and objects.
+ Added "namespaces" option to "parse()". When it is enabled the dots in the
+ keys will be interpreted as namespaces.
+ Added "vars" option to "parse()". When the variables are enabled and a
+ variable does not exist it first looks into the "vars" object before
+ throwing an error. It can be used to pass environment variables.
+ Added "strict" option to "parse()". When it is enabled the parser will only
+ consider as coments and separators the tokens included in the "comments"
+ and "separators" options.
+ Added "include" option to "parse()". The "include" key can be used to import
+ other files.
+ Removed "bufferSize" and "encoding" options. Files are read using a 16KB
+ buffer size and utf8 encoding.
+ Removed the "pretty" option from "stringify()". The required code to
+ accomplish the column limit is too complex and the feature is rarely used.
+ This option contains bugs in the previous versions. The overall stringify
+ speed is faster.
+ The stringify replacer must be a function. Cannot be an array like in previous
+ versions.
+ Some bugfixes with escaped backslashes.
+ Some bugfixes with whitespace values.
+ Some bugfixes with sections.
+ Some bugfixes with "stringify()".
v0.3.3 (12 Jan 2013)
- Fixed column width in pretty feature.
+ Fixed column width in pretty feature.
v0.3.2 (04 Jan 2013)
- Removed "config()".
+ Removed "config()".
v0.3.1 (01 Jan 2013)
- Fixed pretty print with sections and comments.
+ Fixed pretty print with sections and comments.
v0.3.0 (30 Dec 2012)
- Added "reviver" callback setting to "load()".
- Added "replacer" callback setting to "store()".
- Added "pretty" setting to "store()".
- Added "stringify()".
- Added "parse()".
- Merged enhanced-properties module with this module.
- Added sections feature.
- Added custom characters feature.
- Added variable substitution feature.
+ Added "reviver" callback setting to "load()".
+ Added "replacer" callback setting to "store()".
+ Added "pretty" setting to "store()".
+ Added "stringify()".
+ Added "parse()".
+ Merged enhanced-properties module with this module.
+ Added sections feature.
+ Added custom characters feature.
+ Added variable substitution feature.
v0.2.0 (14 Dec 2012)
- Complete code revision and refactor.
- Non printable characters (C0 and C1 control codes) are converted to unicode
- string representations regardless the encoding.
- Added "config()".
+ Complete code revision and refactor.
+ Non printable characters (C0 and C1 control codes) are converted to unicode
+ string representations regardless the encoding.
+ Added "config()".
v0.1.13 (30 Jul 2012)
- Added the option to pass the file encoding, by default is utf8.
+ Added the option to pass the file encoding, by default is utf8.
v0.1.12 (29 Jul 2012)
- Fixed error when "get()" was called with not existent key.
+ Fixed error when "get()" was called with not existent key.
v0.1.11 (23 Jul 2012)
- Fixed case sensitivity.
+ Fixed case sensitivity.
v0.1.10 (22 Jul 2012)
- The empty keys now have a "null" value instead of an empty string.
+ The empty keys now have a "null" value instead of an empty string.
v0.1.9 (22 Jul 2012)
- Added "remove()" method.
+ Added "remove()" method.
v0.1.8 (21 Jul 2012)
- Added the option to configure the case sensitivity.
+ Added the option to configure the case sensitivity.
v0.1.7 (02 May 2012)
- Changed the way to require the class.
- Now: "var Properties = require ("properties");".
- Inside the "load()" and "store()" callbacks, "this" points to the object
- itself.
- Some maintenance.
+ Changed the way to require the class.
+ Now: "var Properties = require ("properties");".
+ Inside the "load()" and "store()" callbacks, "this" points to the object
+ itself.
+ Some maintenance.
v0.1.6 (02 May 2012)
- Fixed source code to support the new `BufferedReader` settings.
+ Fixed source code to support the new `BufferedReader` settings.
v0.1.5 (28 Apr 2012)
- Added "buffered-writer" dependency.
+ Added "buffered-writer" dependency.
v0.1.4 (21 Apr 2012)
- Added "buffered-writer" dependency.
+ Added "buffered-writer" dependency.
v0.1.3 (16 Apr 2012)
- Removed "getFileName()", internal function.
+ Removed "getFileName()", internal function.
v0.1.2 (15 Apr 2012)
- The property value is now converted to a string before persisting.
+ The property value is now converted to a string before persisting.
v0.1.1 (15 Apr 2012)
- Now it's possible to add comments for each key-value pair. A header comment
- can also be added.
+ Now it's possible to add comments for each key-value pair. A header comment
+ can also be added.
v0.1.0 (15 Apr 2012)
- First release.
+ First release.
View
@@ -23,7 +23,7 @@ b: 2
```javascript
var properties = require ("properties");
-properties.load ("file", { path: true }, function (error, obj){
+properties.parse ("file", { path: true }, function (error, obj){
if (error) return console.error (error);
console.log (obj);
@@ -133,7 +133,7 @@ You can also pass external variables with the `vars` option and use their value
<a name="namespaces"></a>
__Namespaces__
-When the `namespaces` option is enabled dot separated keys are parsed as namespaces, that is, they are interpreted as JavaScript objects.
+When the `namespaces` option is enabled dot separated keys and sections are parsed as namespaces, that is, they are interpreted as JavaScript objects.
```
a.b = 1
@@ -157,27 +157,29 @@ These properties create the following object:
You can also use sections and variables:
```
-[s1]
+[s1.x]
a.b = 1
# a.c.d = 1
-a.c.d = ${s1|a.b}
+a.c.d = ${s1.x|a.b}
```
```javascript
{
s1: {
- a: {
- b: 1,
- c: {
- d: 1
+ x: {
+ a: {
+ b: 1,
+ c: {
+ d: 1
+ }
}
}
}
}
```
-The external variables can also be read using namespaces:
+The external variables can be also read using namespaces:
```javascript
var options = {
@@ -223,7 +225,7 @@ Note: The whitespace (`<space>`, `\t`, `\f`) is still considered a separator eve
<a name="include"></a>
__Importing files__
-When the `include` option is enabled, the `include` key allows you import files. If the path is a directory it tries to load the file `index.properties`. The paths are relative from the __current__ .properties file.
+When the `include` option is enabled, the `include` key allow you import files. If the path is a directory it tries to load the file `index.properties`. The paths are relative to the __current__ .properties file.
The imported files are merged with the current file, they can replace old data.
@@ -266,17 +268,23 @@ There are too many options that you can enable but, which of them should you use
db_pool_min 5
db_pool_max 10
```
-- __sections__: More organization. You don't need to write the first namespace level. For example:
+- __sections__: More organization. You don't need to write all the namespace chain. For example:
```
[db]
- pool.min 5
- pool.max 10
+ host 1.2.3.4
+ port 1234
+
+ [db.pool]
+ min 5
+ max 10
```
Instead of:
```
+ db.host 1.2.3.4
+ db.port 1234
db.pool.min 5
db.pool.max 10
```
@@ -329,6 +337,8 @@ config.load (function (error, obj){
});
```
+Note: You can also use a configuration loader like [seraphim](https://github.com/gagle/node-seraphim).
+
---
<a name="parse"></a>
@@ -339,10 +349,16 @@ Parses a .properties string.
If a callback is given, the result is returned as the second parameter.
```javascript
-obj = properties.parse ({ ... });
+try{
+ //Certain options can throw errors, so if the callback is not used, try-catch
+ //the function
+ obj = properties.parse ({ ... });
+}catch (error){
+ ...
+}
properties.parse ({ ... }, function (error, obj){
- //The "error" can be ignored, it is always null if the "path" option is not used
+ //The callback must be used if the "path" option is used
});
```
@@ -367,15 +383,15 @@ Options:
- __strict__ - _Boolean_
This option can be used with the `comments` and `separators` options. If true, __only__ the tokens specified in these options are used to parse comments and separators.
- __sections__ - _Boolean_
- Parses INI sections. See the [ini](#ini) section for further details.
+ Parses INI sections. Read the [INI](#ini) section for further details.
- __namespaces__ - _Boolean_
- Parses dot separated keys as JavaScript objects. See the [namespaces](#namespaces) section for further details.
+ Parses dot separated keys as JavaScript objects. Look at the [namespaces](#namespaces) section for further details.
- __variables__ - _Boolean_
- Allows you to read the value of a key while the file is being parsed. See the [variables](#variables) section for further details.
+ Allows you to read the value of a key while the file is being parsed. Look at the [variables](#variables) section for further details.
- __vars__ - _Boolean_
- External variables can be passed to the file if the variables option is enabled. See the [variables](#variables) section for further details.
+ External variables can be passed to the file if the variables option is enabled. Look at the [variables](#variables) section for further details.
- __include__ - _Boolean_
- Files can be linked and imported with the `include` key. If this option is used the callback is mandatory. See the [include](#include) section for further details.
+ Files can be linked and imported with the `include` key. If this option is used the callback is mandatory. Look at the [include](#include) section for further details.
- __reviver__ - _Function_
Each property or section can be removed or modified from the final object. It's similar to the reviver of the `JSON.parse()` function.
@@ -470,9 +486,9 @@ ___module_.stringify(obj[, options][, callback]) : undefined | String__
Stringifies an object or a [Stringifier](#Stringifier).
-If you don't need to add sections nor comments simply pass an object, otherwise use a [Stringifier](#Stringifier).
+If you don't need to add sections or comments simply pass an object, otherwise use a [Stringifier](#Stringifier).
-The callback is only needed when the `path` option is used.
+The callback is only necessary when the `path` option is used.
Nested objects and arrays cannot be stringified like in JSON.stringify:
Oops, something went wrong.

0 comments on commit 5639dca

Please sign in to comment.