Comparing version 1.0.1 to 1.1.0
20
index.js
'use strict' | ||
var split = require('dot-parts') | ||
var balanced = require('balanced-match') | ||
var ap = require('ap') | ||
var findCall = ap.partial(balanced, '(', ')') | ||
@@ -10,3 +13,18 @@ module.exports = function createAccessor (source, path) { | ||
function accumulate (statement, property) { | ||
return statement + "['" + property + "']" | ||
var callString = '' | ||
function append (body) { | ||
callString += '(' + body + ')' | ||
} | ||
var call = findCall(property) | ||
if (call) { | ||
property = call.pre | ||
append(call.body) | ||
var post = call.post | ||
} | ||
while (post) { | ||
call = findCall(post) | ||
append(call.body) | ||
post = call.post | ||
} | ||
return statement + "['" + property + "']" + callString | ||
} |
{ | ||
"name": "accessory", | ||
"main": "index.js", | ||
"version": "1.0.1", | ||
"description": "Create property accessor statements for dot paths", | ||
"version": "1.1.0", | ||
"description": "Create property accessor/caller statements for dot paths", | ||
"license": "MIT", | ||
@@ -32,4 +32,6 @@ "repository": "bendrucker/accessory", | ||
"dependencies": { | ||
"ap": "~0.2.0", | ||
"balanced-match": "~0.2.0", | ||
"dot-parts": "~1.0.0" | ||
} | ||
} |
# accessory [![Build Status](https://travis-ci.org/bendrucker/accessory.svg?branch=master)](https://travis-ci.org/bendrucker/accessory) | ||
> Create property accessor statements for dot paths | ||
> Create property accessor/caller statements for dot paths | ||
@@ -23,2 +23,5 @@ | ||
//=> window['foo.bar'] | ||
accessory('window', 'foo.bar(baz)') | ||
//=> window['foo']['bar'](baz) | ||
``` | ||
@@ -42,3 +45,3 @@ | ||
A dot property path. | ||
A dot property path, including function calls. | ||
@@ -45,0 +48,0 @@ |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3257
26
50
0
3
+ Addedap@~0.2.0
+ Addedbalanced-match@~0.2.0
+ Addedap@0.2.0(transitive)
+ Addedbalanced-match@0.2.1(transitive)