endpoint-parser
Little module that helps with endpoints parsing.
API
.decompose(endpoint)
Decomposes a endpoint into name
, source
and target
.
var endpointParser = ; endpointParser;// { name: '', source: 'jquery', target: '~2.0.0' } endpointParser;// { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' } endpointParser;// { name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' } endpointParser;// { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
.compose(decEndpoint)
Inverse of decompose()
.
Takes a decomposed endpoint and composes it back into a string.
var endpointParser = ; endpointParser;// jquery#~2.0.0 endpointParser;// backbone=backbone-amd#~1.0.0 endpointParser;// http://twitter.github.io/bootstrap/assets/bootstrap.zip endpointParser;// bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip
.json2decomposed(key, value)
Similar to decompose()
but specially designed to be used when parsing bower.json
dependencies.
For instance, in a bower.json
like this:
"name": "foo" "version": "0.1.0" "dependencies": "jquery": "~1.9.1" "backbone": "backbone-amd#~1.0.0" "bootstrap": "http://twitter.github.io/bootstrap/assets/bootstrap"
You would call json2decomposed
like so:
endpointParser;// { name: 'jquery', source: 'jquery', target: '~1.9.1' } endpointParser;// { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' } endpointParser;// { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
.decomposed2json(decEndpoint)
Inverse of json2decomposed()
.
Takes a decomposed endpoint and composes it to be saved to bower.json
.
var endpointParser = ; endpointParser;// { jquery: '~2.0.0' } endpointParser;// { backbone: 'backbone-amd#~2.0.0' } endpointParser;// { bootstrap: 'http://twitter.github.io/bootstrap/assets/bootstrap' }
This function throws an exception if the name
from the decomposed endpoint is empty.
License
Released under the MIT License.