Dot Notes: a simple module for parsing dot notation
Due to this, I decided to write dot-notes, a simple npm module for converting an Object to it's dotted form (and back again). This library has full coverage, and is pretty easy to use. It uses the following syntax for notation:
non-specialkeys are separated by a period
Keys containing special characters are placed in square brackets and wrapped in quotes
['key'], and are not preceeded by a period. Such keys are also followed by a period only if the following key is a
Arrays are also traversed, and are represented by an index in square brackets
. These keys are followed by a period only if the following key is a non-special key.
// Any key may be reference via dot separators test.one; // Array elements must be wrapped in square brackets test.one; // Keys with special characters must go in quotes, in square brackets test.one['my.test']; // Quotes can be either double or single, as long as they match test.one["my.test"]; // Should you wish to, you can place non-special keys in this form, it won't harm anything test['one'];
You can use dot-notes to translate an Object into a noted form, a noted Object back into the original, and a String following the above syntax to create an Object. All information around how to do this can be found on npm and the GitHub repo.
I don't expect many people will find a need for this (even my needs are quite specific to a project), but it's always better to have something for it than not! Oh and if there's something I'm missing with regards to syntax, or if there's a syntax which is more widely accepted that I'm somehow missing, feel free to let me know and I'll consider switching over (or adding support, whichever).