Skip to content

Commit

Permalink
Add new join function and various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfin committed Oct 14, 2018
1 parent 7effeb4 commit cc7cfce
Show file tree
Hide file tree
Showing 31 changed files with 2,271 additions and 448 deletions.
22 changes: 22 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
environment:
matrix:
- nodejs_version: "10"
- nodejs_version: "8"
- nodejs_version: "6"
- nodejs_version: "4"
- nodejs_version: "0.12"
- nodejs_version: "0.10"

init:
- git config --global core.autocrlf true

install:
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- node --version
- npm --version
- npm test

build: off
5 changes: 0 additions & 5 deletions .codeclimate.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/coverage
/node_modules
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
"axway/env-node",
"axway/+mocha"
],
"rules": {
"indent": [ "error", 2, { "SwitchCase": 1 } ],
"security/detect-non-literal-regexp": "off"
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
15 changes: 3 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Coverage directory used by tools like istanbul
coverage

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# tmp
.tmp

# idea
.idea
/.idea
/coverage
/node_modules
31 changes: 0 additions & 31 deletions .jscsrc

This file was deleted.

1 change: 0 additions & 1 deletion .jshintignore

This file was deleted.

29 changes: 0 additions & 29 deletions .jshintrc

This file was deleted.

6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
sudo: false
node_js:
- "stable"
- "8"
- "6"
- "4"
- "0.12"
- "0.10"
- "0.10"
94 changes: 0 additions & 94 deletions Gruntfile.js

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dot-notes [![Build Status](https://travis-ci.org/zackehh/dot-notes.svg?branch=master)](https://travis-ci.org/zackehh/dot-notes) [![Code Climate](https://codeclimate.com/github/zackehh/dot-notes/badges/gpa.svg)](https://codeclimate.com/github/zackehh/dot-notes) [![Test Coverage](https://codeclimate.com/github/zackehh/dot-notes/badges/coverage.svg)](https://codeclimate.com/github/zackehh/dot-notes)
=========
# dot-notes
[![Build Status](https://travis-ci.org/zackehh/dot-notes.svg?branch=master)](https://travis-ci.org/zackehh/dot-notes) [![Code Climate](https://codeclimate.com/github/zackehh/dot-notes/badges/gpa.svg)](https://codeclimate.com/github/zackehh/dot-notes) [![Test Coverage](https://codeclimate.com/github/zackehh/dot-notes/badges/coverage.svg)](https://codeclimate.com/github/zackehh/dot-notes)

This module provides a simple way of constructing/parsing dot/bracket notation in JavaScript/Node.js. It was born from a need to flatten Objects in a customized way, making `dot-notes` useful in many scenarios.

Expand Down Expand Up @@ -60,4 +60,4 @@ Tests can be run as follows:
$ npm test
$ grunt test
$ grunt # runs the default Travis loop
```
```
11 changes: 2 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
module.exports = {

create: require('./lib/create'),

escape: require('./lib/escape'),

isEscaped: require('./lib/escaped'),

get: require('./lib/get'),

join: require('./lib/join'),
keys: require('./lib/keys'),

recurse: require('./lib/recurse'),

ParseException: require('./lib/exception')

};
};
28 changes: 17 additions & 11 deletions lib/create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const parse
= require('./keys');
var parse = require('./keys');

/**
* Constructs a key based on a dot noted path and
Expand All @@ -8,10 +7,14 @@ const parse
* will be constructed appropriately (i.e. an Array
* where necessary).
*
* @param obj the target (destination) Object
* @param str the string path to create
* @param val the value to set the key against
* @returns {*} an Object containing the set value
* @param {object} obj
* the target (destination) Object
* @param {string} str
* the string path to create
* @param {*} val
* the value to set the key against
* @returns {object}
* an Object containing the set value
*/
function create(obj, str, val) {
var keys = parse(str);
Expand All @@ -25,8 +28,9 @@ function create(obj, str, val) {
}

var tmp = container;
var last = keys.length - 1;

for (var k = 0, j = keys.length - 1; k < j; k++) {
for (var k = 0; k < last; k++) {
var key = keys[k];

if (!tmp[key]) {
Expand All @@ -36,7 +40,7 @@ function create(obj, str, val) {
tmp = tmp[key];
}

tmp[keys[j]] = val;
tmp[keys[last]] = val;

return container;
}
Expand All @@ -46,8 +50,10 @@ function create(obj, str, val) {
* an Object, based on whether the key is a Number
* or not.
*
* @param key the key to check
* @returns {*} an Array if the key is a Number
* @param {string} key
* the key to check
* @returns {*}
* an Array if the key is a Number
*/
function typed(key) {
return typeof key === 'number' ? [] : {};
Expand All @@ -59,4 +65,4 @@ function typed(key) {
*
* @type {create}
*/
module.exports = create;
module.exports = create;
14 changes: 7 additions & 7 deletions lib/escape.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const ParseException
= require('./exception');
const patterns
= require('./patterns');
var ParseException = require('./exception');
var patterns = require('./patterns');

/**
* Escapes a key based on the content, parsing into
* a dot noted path entry. Number keys will be treated
* as Array indices.
*
* @param input the key to escape
* @returns {*} a String containing the escaped key
* @param {string} input
* the key to escape
* @returns {string}
* a String containing the escaped key
*/
function escape(input) {
var type = typeof input;
Expand Down Expand Up @@ -41,4 +41,4 @@ function escape(input) {
*
* @type {create}
*/
module.exports = escape;
module.exports = escape;
11 changes: 6 additions & 5 deletions lib/escaped.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const patterns
= require('./patterns');
var patterns = require('./patterns');

/**
* A shorthand to check whether an input is escaped
* dot-notation. This can be used to validate a
* specify key.
*
* @param input the input to validate
* @returns {*} true if the key is escaped
* @param {string} input
* the input to validate
* @returns {boolean}
* true if the key is escaped
*/
function escaped(input) {
var m;
Expand All @@ -22,4 +23,4 @@ function escaped(input) {
*
* @type {escaped}
*/
module.exports = escaped;
module.exports = escaped;
Loading

0 comments on commit cc7cfce

Please sign in to comment.