mirror of
https://github.com/bower/bower.git
synced 2026-04-24 03:00:19 -04:00
Initial commit.
This commit is contained in:
8
packages/bower-endpoint-parser/.editorconfig
Normal file
8
packages/bower-endpoint-parser/.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
2
packages/bower-endpoint-parser/.gitignore
vendored
Normal file
2
packages/bower-endpoint-parser/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules
|
||||
/npm-debug.*
|
||||
61
packages/bower-endpoint-parser/.jshintrc
Normal file
61
packages/bower-endpoint-parser/.jshintrc
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"predef": [
|
||||
"console",
|
||||
"describe",
|
||||
"it",
|
||||
"after",
|
||||
"afterEach",
|
||||
"before",
|
||||
"beforeEach"
|
||||
],
|
||||
|
||||
"indent": 4,
|
||||
"node": true,
|
||||
"devel": true,
|
||||
|
||||
"bitwise": false,
|
||||
"curly": false,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"latedef": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": true,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"quotmark": "single",
|
||||
"strict": false,
|
||||
"trailing": true,
|
||||
"camelcase": true,
|
||||
|
||||
"asi": false,
|
||||
"boss": true,
|
||||
"debug": false,
|
||||
"eqnull": true,
|
||||
"esnext": false,
|
||||
"evil": false,
|
||||
"expr": true,
|
||||
"funcscope": false,
|
||||
"globalstrict": false,
|
||||
"iterator": false,
|
||||
"lastsemic": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": false,
|
||||
"loopfunc": true,
|
||||
"multistr": false,
|
||||
"onecase": true,
|
||||
"regexdash": false,
|
||||
"scripturl": false,
|
||||
"smarttabs": false,
|
||||
"shadow": false,
|
||||
"sub": false,
|
||||
"supernew": true,
|
||||
"validthis": false,
|
||||
|
||||
"nomen": false,
|
||||
"white": true
|
||||
}
|
||||
4
packages/bower-endpoint-parser/.travis.yml
Normal file
4
packages/bower-endpoint-parser/.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
19
packages/bower-endpoint-parser/LICENSE
Normal file
19
packages/bower-endpoint-parser/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 Twitter and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
100
packages/bower-endpoint-parser/README.md
Normal file
100
packages/bower-endpoint-parser/README.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# bower-endpoint-parser [](http://travis-ci.org/bower/endpoint-parser)
|
||||
|
||||
Little module that helps with endpoints parsing.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### .decompose(endpoint)
|
||||
|
||||
Decomposes a endpoint into `name`, `source` and `target`.
|
||||
|
||||
```js
|
||||
var endpointParser = require('bower-endpoint-parser');
|
||||
|
||||
endpointParser.decompose('jquery#~2.0.0');
|
||||
// { name: '', source: 'jquery', target: '~2.0.0' }
|
||||
|
||||
endpointParser.decompose('backbone=backbone-amd#~1.0.0');
|
||||
// { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' }
|
||||
|
||||
endpointParser.decompose('http://twitter.github.io/bootstrap/assets/bootstrap.zip');
|
||||
// { name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
|
||||
|
||||
endpointParser.decompose('bootstrap=http://twitter.github.io/bootstrap/assets/bootstrap.zip');
|
||||
// { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
|
||||
```
|
||||
|
||||
### .compose(decEndpoint)
|
||||
|
||||
Inverse of `compose()`.
|
||||
Takes a decomposed endpoint and composes it back into a string.
|
||||
|
||||
```js
|
||||
var endpointParser = require('bower-endpoint-parser');
|
||||
|
||||
endpointParser.compose({ name: '', source: 'jquery', target: '~2.0.0' });
|
||||
// jquery=~2.0.0
|
||||
|
||||
endpointParser.compose({ name: 'backbone', source: 'backbone-amd', target: '~1.0.0' });
|
||||
// backbone=backbone-amd#~1.0.0
|
||||
|
||||
endpointParser.compose({ name: '', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' });
|
||||
// http://twitter.github.io/bootstrap/assets/bootstrap.zip
|
||||
|
||||
endpointParser.compose({ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' });
|
||||
// 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:
|
||||
|
||||
```js
|
||||
{
|
||||
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.json2decomposed('jquery', '~1.9.1');
|
||||
// { name: 'jquery', source: 'jquery', target: '~1.9.1' }
|
||||
|
||||
endpointParser.json2decomposed('backbone', 'backbone-amd#~1.0.0');
|
||||
// { name: 'backbone', source: 'backbone-amd', target: '~1.0.0' }
|
||||
|
||||
endpointParser.json2decomposed('bootstrap', 'http://twitter.github.io/bootstrap/assets/bootstrap');
|
||||
// { name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' }
|
||||
```
|
||||
|
||||
### .decomposed2json(decEndpoint)
|
||||
|
||||
Inverse of `json2decomposed()`.
|
||||
Takes a decomposed endpoint and composes it to an object.
|
||||
|
||||
```js
|
||||
var endpointParser = require('bower-endpoint-parser');
|
||||
|
||||
endpointParser.decomposed2json({ name: '', source: 'jquery', target: '~2.0.0' });
|
||||
// { jquery: '~2.0.0' }
|
||||
|
||||
endpointParser.decomposed2json({ name: 'backbone', source: 'backbone-amd', target: '~1.0.0' });
|
||||
// { backbone: 'backbone-amd#~2.0.0' }
|
||||
|
||||
endpointParser.decomposed2json({ name: 'bootstrap', source: 'http://twitter.github.io/bootstrap/assets/bootstrap', target: '*' });
|
||||
// { backbone: 'http://twitter.github.io/bootstrap/assets/bootstrap' }
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
|
||||
88
packages/bower-endpoint-parser/index.js
Normal file
88
packages/bower-endpoint-parser/index.js
Normal file
@@ -0,0 +1,88 @@
|
||||
function decompose(endpoint) {
|
||||
var regExp = /^(?:([\w\-]|(?:[\w\.\-]+[\w\-])?)=)?([^\|#]+)(?:#(.*))?$/;
|
||||
var matches = endpoint.match(regExp);
|
||||
var target;
|
||||
var error;
|
||||
|
||||
if (!matches) {
|
||||
error = new Error('Invalid endpoint: ' + endpoint);
|
||||
error.code = 'EINVEND';
|
||||
throw error;
|
||||
}
|
||||
|
||||
target = matches[3];
|
||||
|
||||
return {
|
||||
name: matches[1] || '',
|
||||
source: matches[2],
|
||||
target: !target || target === 'latest' ? '*' : target
|
||||
};
|
||||
}
|
||||
|
||||
function compose(decEndpoint) {
|
||||
var composed = '';
|
||||
|
||||
if (decEndpoint.name) {
|
||||
composed += decEndpoint.name + '=';
|
||||
}
|
||||
|
||||
composed += decEndpoint.source;
|
||||
|
||||
if (!isWildcard(decEndpoint.target)) {
|
||||
composed += '#' + decEndpoint.target;
|
||||
}
|
||||
|
||||
return composed;
|
||||
}
|
||||
|
||||
function json2decomposed(key, value) {
|
||||
var endpoint = key + '=';
|
||||
var split = value.split('#');
|
||||
|
||||
// If # was found, the source was specified
|
||||
if (split.length > 1) {
|
||||
endpoint += split[0] + '#' + split[1];
|
||||
// If value has a /, it's probably a source
|
||||
} else if (value.indexOf('/') !== -1) {
|
||||
endpoint += value + '#*';
|
||||
// Otherwise use the key as the source
|
||||
} else {
|
||||
endpoint += key + '#' + split[0];
|
||||
}
|
||||
|
||||
return decompose(endpoint);
|
||||
}
|
||||
|
||||
function decomposed2json(decEndpoint) {
|
||||
var error;
|
||||
var key = decEndpoint.name;
|
||||
var value = '';
|
||||
var ret = {};
|
||||
|
||||
if (!key) {
|
||||
error = new Error('Decomposed endpoint must have a name');
|
||||
error.code = 'EINVEND';
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (decEndpoint.source !== decEndpoint.name) {
|
||||
value += decEndpoint.source + '#';
|
||||
}
|
||||
|
||||
if (!isWildcard(decEndpoint.target)) {
|
||||
value += decEndpoint.target;
|
||||
}
|
||||
|
||||
ret[key] = value;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function isWildcard(target) {
|
||||
return !target || target === '*' || target === 'latest';
|
||||
}
|
||||
|
||||
module.exports.decompose = decompose;
|
||||
module.exports.compose = compose;
|
||||
module.exports.json2decomposed = json2decomposed;
|
||||
module.exports.decomposed2json = decomposed2json;
|
||||
27
packages/bower-endpoint-parser/package.json
Normal file
27
packages/bower-endpoint-parser/package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "bower-endpoint-parser",
|
||||
"version": "0.1.0-rc.1",
|
||||
"description": "Little module that helps with endpoints parsing.",
|
||||
"author": "Twitter",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/bower/endpoint-parser/blob/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/bower/endpoint-parser.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"expect.js": "~0.2.0",
|
||||
"mocha": "~1.12.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm test"
|
||||
}
|
||||
}
|
||||
1
packages/bower-endpoint-parser/test/test.js
Normal file
1
packages/bower-endpoint-parser/test/test.js
Normal file
@@ -0,0 +1 @@
|
||||
// TODO
|
||||
Reference in New Issue
Block a user