expand-object
Advanced tools
Comparing version 0.4.0 to 0.4.1
27
cli.js
@@ -9,5 +9,2 @@ #!/usr/bin/env node | ||
var stdin = require('get-stdin'); | ||
var Store = require('data-store'); | ||
var store = new Store('expand-object'); | ||
var expand = require('./index'); | ||
@@ -39,19 +36,7 @@ var pkg = require('./package.json'); | ||
function run(contents) { | ||
if (argv.get) { | ||
output = store.get(argv.get); | ||
console.log(output); | ||
return; | ||
var output = expand(contents); | ||
if (!argv.raw) { | ||
output = JSON.stringify(output); | ||
} | ||
var output = contents; | ||
if (argv.set) { | ||
output = expand(argv.set); | ||
store.set(output); | ||
} else { | ||
output = expand(contents); | ||
if (!argv.raw) { | ||
output = JSON.stringify(output); | ||
} | ||
} | ||
console.log(output); | ||
@@ -62,7 +47,7 @@ process.exit(0); | ||
if (!process.stdin.isTTY) { | ||
return stdin(function(contents) { | ||
stdin(function(contents) { | ||
run(contents); | ||
}); | ||
} else { | ||
run(argv._[0] || ''); | ||
} | ||
run(argv._[0] || ''); |
44
index.js
@@ -40,2 +40,8 @@ 'use strict'; | ||
var val = arr[i]; | ||
// test for `https://foo` | ||
if (/\w:\/\/\w/.test(val)) { | ||
res[val] = ''; | ||
continue; | ||
} | ||
var re = /^((?:\w+)\.(?:\w+))[:.]((?:\w+,)+)+((?:\w+):(?:\w+))/; | ||
@@ -139,3 +145,3 @@ var m = re.exec(val); | ||
function expandArrayObj(str, opts) { | ||
var m = /\w+:.*:/.exec(str); | ||
var m = /\w+:.*?:/.exec(str); | ||
if (!m) return expandArray(str, opts); | ||
@@ -188,34 +194,14 @@ | ||
str = String(str); | ||
var len = str.length, i = -1; | ||
var segs = str.split(ch); | ||
var len = segs.length; | ||
var res = []; | ||
var seg = ''; | ||
var i = -1; | ||
while (++i < len) { | ||
var curr = str[i]; | ||
if (curr === '/') { | ||
seg += curr; | ||
while ((curr = str[++i]) !== '/') { | ||
if (i >= len) { | ||
res.push(seg); | ||
break; | ||
} | ||
seg += curr; | ||
} | ||
var key = segs[i]; | ||
while (key[key.length - 1] === '\\') { | ||
key = key.slice(0, -1) + ch + segs[++i]; | ||
} | ||
if (curr !== ch) { | ||
if (curr === '\\' && str[i + 1] === ch) { | ||
curr = ch; | ||
} | ||
seg += curr; | ||
} else if (str[i - 1] !== '\\') { | ||
res.push(seg); | ||
seg = ''; | ||
} | ||
if (i === len - 1 && seg && (str[i - 1] !== '\\')) { | ||
res.push(seg); | ||
seg = ''; | ||
} | ||
res.push(key); | ||
} | ||
@@ -222,0 +208,0 @@ return res; |
{ | ||
"name": "expand-object", | ||
"description": "Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib.", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"homepage": "https://github.com/jonschlinkert/expand-object", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/expand-object", | ||
"bugs": "https://github.com/jonschlinkert/expand-object/issues", | ||
"bugs": { | ||
"bugs": "https://github.com/jonschlinkert/expand-object/issues" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
"cli.js", | ||
"index.js" | ||
], | ||
@@ -26,7 +28,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"data-store": "^0.11.1", | ||
"get-stdin": "^5.0.0", | ||
"is-number": "^2.0.2", | ||
"get-stdin": "^5.0.1", | ||
"is-number": "^2.1.0", | ||
"minimist": "^1.2.0", | ||
"set-value": "^0.3.0" | ||
"set-value": "^0.3.2" | ||
}, | ||
@@ -56,4 +57,11 @@ "devDependencies": { | ||
"list": "expand-args" | ||
} | ||
}, | ||
"reflinks": [ | ||
"collapse-object" | ||
], | ||
"layout": "default", | ||
"plugins": [ | ||
"gulp-format-md" | ||
] | ||
} | ||
} | ||
} |
@@ -1,7 +0,36 @@ | ||
# expand-object [](http://badge.fury.io/js/expand-object) | ||
# expand-object [](https://www.npmjs.com/package/expand-object) [](https://travis-ci.org/jonschlinkert/expand-object) | ||
> Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib. | ||
Also see [collapse-object][], for doing the reverse of this library. | ||
- [Install](#install) | ||
* [Type casting](#type-casting) | ||
- [Install](#install-1) | ||
- [CLI](#cli) | ||
- [node.js](#nodejs) | ||
* [children](#children) | ||
* [siblings](#siblings) | ||
+ [general siblings](#general-siblings) | ||
+ [adjacent siblings](#adjacent-siblings) | ||
+ [difference between sibling types](#difference-between-sibling-types) | ||
* [key-value pairs](#key-value-pairs) | ||
* [arrays](#arrays) | ||
- [Usage examples](#usage-examples) | ||
- [Related projects](#related-projects) | ||
- [Running tests](#running-tests) | ||
- [Contributing](#contributing) | ||
- [Author](#author) | ||
- [License](#license) | ||
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ | ||
## Install | ||
Install with [npm](https://www.npmjs.com/) | ||
```sh | ||
$ npm i expand-object --save | ||
``` | ||
Also see [collapse-object](https://github.com/jonschlinkert/collapse-object), for doing the reverse of this library. | ||
**Examples** | ||
@@ -261,3 +290,3 @@ | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](/new). | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/expand-object/issues/new). | ||
@@ -268,8 +297,8 @@ ## Author | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright © 2015 Jon Schlinkert | ||
Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the MIT license. | ||
@@ -279,4 +308,2 @@ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 02, 2015._ | ||
[collapse-object]: https://github.com/jonschlinkert/collapse-object | ||
_This file was generated by [verb](https://github.com/verbose/verb) on December 23, 2015._ |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
14018
4
306
220
- Removeddata-store@^0.11.1
- Removedarr-union@3.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbase-methods@0.3.1(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedclass-utils@0.2.3(transitive)
- Removedcollection-visit@0.2.3(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddata-store@0.11.1(transitive)
- Removeddefine-property@0.2.5(transitive)
- Removedexpand-tilde@1.2.2(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedget-value@1.3.12.0.6(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobal-modules@0.2.3(transitive)
- Removedglobal-prefix@0.1.5(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-own-deep@0.1.4(transitive)
- Removedhas-value@0.2.10.3.1(transitive)
- Removedhas-values@0.1.4(transitive)
- Removedhomedir-polyfill@1.0.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedini@1.3.8(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.7(transitive)
- Removedis-windows@0.2.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedisobject@1.0.23.0.1(transitive)
- Removedkind-of@2.0.1(transitive)
- Removedlazy-cache@0.2.72.0.2(transitive)
- Removedmap-visit@0.1.5(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednoncharacters@1.1.0(transitive)
- Removedobject-visit@0.3.4(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedparse-passwd@1.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedresolve-dir@0.1.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedset-getter@0.1.1(transitive)
- Removedset-value@0.2.0(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedunion-value@0.1.1(transitive)
- Removedunset-value@0.1.2(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedget-stdin@^5.0.1
Updatedis-number@^2.1.0
Updatedset-value@^0.3.2