Skip to content

Commit

Permalink
Fixing Issues #44, #47 - Improving package manager integration with U…
Browse files Browse the repository at this point in the history
…MD returnExports
  • Loading branch information
rodneyrehm committed Nov 3, 2012
1 parent d3f9c45 commit 7039230
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 69 deletions.
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,46 @@ URI.expand("/foo/{dir}/{file}", {

See the [About Page](http://medialize.github.com/URI.js/) and [API Docs](http://medialize.github.com/URI.js/docs.html) for more stuff.

## Using URI.js ##

## npm ##
### Browser ###

```
npm install URIjs
```
I guess you'll manage to use the [build tool](http://medialize.github.com/URI.js/build.html) or follow the [instructions below](#minify) to combine and minify the various files into URI.min.js - and I'm fairly certain you know how to `<script src=".../URI.min.js"></script>` that sucker, too.

### Node.js and NPM ###

## Server-side JS ##
Install with `npm install URIjs` or add `"URIjs"` to the dependencies in your `package.json`.

```javascript
// load URI.js
var URI = require('URIjs');
// load an optional module (e.g. URITemplate)
var URITemplate = require('URIjs/src/URITemplate');

URI("/foo/bar/baz.html")
.relativeTo("/foo/bar/sub/world.html")
// -> ../baz.html
```

### RequireJS ###

Clone the URI.js repository or use a package manager to get URI.js into your project.

```javascript
require.config({
paths: {
URIjs: '../node_modules/URIjs/src'
}
});

require(['URIjs/URI'], function(URI) {
console.log("URI.js and dependencies: ", URI("//amazon.co.uk").is('sld') ? 'loaded' : 'failed');
});
require(['URIjs/URITemplate'], function(URITemplate) {
console.log("URITemplate.js and dependencies: ", URITemplate._cache ? 'loaded' : 'failed');
});
```

## Minify ##

See the [build tool](http://medialize.github.com/URI.js/build.html) or use [Google Closure Compiler](http://closure-compiler.appspot.com/home):
Expand Down Expand Up @@ -197,10 +219,9 @@ URI.js is published under the [MIT license](http://www.opensource.org/licenses/m
* adding jQuery 1.8.x compatibility for jQuery.URI.js
* fixing `URI(location)` to properly parse the URL - ([Issue #50](https://github.com/medialize/URI.js/issues/50))
* updating [Punycode.js](https://github.com/bestiejs/punycode.js/) to version 1.1.1
* improving AMD/Node using [UMD returnExports](https://github.com/umdjs/umd/blob/master/returnExports.js) - ([Issue #44](https://github.com/medialize/URI.js/issues/44), [Issue #47](https://github.com/medialize/URI.js/issues/47))

// TODO: remaining for 1.8.0

* improving AMD/Node using [UMD returnExportsGlobal](https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js)
* add to jam.js
* run tests in node.js
* document encode/decode functions
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"src/IPv6.js",
"src/SecondLevelDomains.js",
"src/punycode.js",
"src/URITemplate.js"
"src/URITemplate.js",
"src/jquery.URI.js"
]
}
37 changes: 22 additions & 15 deletions src/IPv6.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,28 @@
* GPL v3 http://opensource.org/licenses/GPL-3.0
*
*/

(function(undefined){
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else {
// Browser globals (root is window)
root.IPv6 = factory();
}
}(this, function () {
"use strict";

var global = typeof module !== 'undefined' && module.exports
? module.exports
: window;
/*
var _in = "fe80:0000:0000:0000:0204:61ff:fe9d:f156",
_out = IPv6.best(_in),
_expected = "fe80::204:61ff:fe9d:f156";
console.log(_in, _out, _expected, _out === _expected);
*/

var best = function(address) {
// based on:
Expand Down Expand Up @@ -152,15 +167,7 @@ var best = function(address) {
return result;
};

global.IPv6 = {
return {
best: best
};
})();

/*
var _in = "fe80:0000:0000:0000:0204:61ff:fe9d:f156",
_out = IPv6.best(_in),
_expected = "fe80::204:61ff:fe9d:f156";
console.log(_in, _out, _expected, _out === _expected);
*/
}));
22 changes: 15 additions & 7 deletions src/SecondLevelDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@
*
*/

(function(undefined){
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else {
// Browser globals (root is window)
root.SecondLevelDomains = factory();
}
}(this, function () {
"use strict";

var SLD = {
Expand Down Expand Up @@ -194,9 +206,5 @@ var SLD = {

SLD.init();

(typeof module !== 'undefined' && module.exports
? module.exports = SLD
: window.SecondLevelDomains = SLD
);

})();
return SLD;
}));
18 changes: 16 additions & 2 deletions src/URI.fragmentQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@
// uri.removeFragment("name");
// uri.toString() === "http://example.org/#?bar=foo";

(function(URI, undefined){
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./URI'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./URI'], factory);
} else {
// Browser globals (root is window)
factory(root.URI);
}
}(this, function (URI) {
"use strict";

var p = URI.prototype,
Expand Down Expand Up @@ -67,4 +79,6 @@ p.removeFragment = function(name, value, build) {
p.addHash = p.addFragment;
p.removeHash = p.removeFragment;

})(window.URI);
// extending existing object rather than defining something new
return {};
}));
18 changes: 16 additions & 2 deletions src/URI.fragmentURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
// furi.pathname('/hello.html');
// uri.toString() === "http://example.org/#!/hello.html"

(function(URI, undefined){
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./URI'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./URI'], factory);
} else {
// Browser globals (root is window)
factory(root.URI);
}
}(this, function (URI) {
"use strict";

var p = URI.prototype,
Expand Down Expand Up @@ -55,4 +67,6 @@ p.build = function(deferBuild) {
return b.call(this, deferBuild);
};

})(window.URI);
// extending existing object rather than defining something new
return {};
}));
32 changes: 16 additions & 16 deletions src/URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
* GPL v3 http://opensource.org/licenses/GPL-3.0
*
*/

(function(undefined) {
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./punycode'), require('./IPv6'), require('./SecondLevelDomains'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./punycode', './IPv6', './SecondLevelDomains'], factory);
} else {
// Browser globals (root is window)
root.URI = factory(root.punycode, root.IPv6, root.SecondLevelDomains);
}
}(this, function (punycode, IPv6, SLD) {
"use strict";

var _use_module = typeof module !== "undefined" && module.exports,
_load_module = function(module) {
return _use_module ? require('./' + module) : window[module];
},
punycode = _load_module('punycode'),
IPv6 = _load_module('IPv6'),
SLD = _load_module('SecondLevelDomains'),
URI = function(url, base) {
var URI = function(url, base) {
// Allow instantiation without the 'new' keyword
if (!(this instanceof URI)) {
return new URI(url, base);
Expand Down Expand Up @@ -1608,9 +1612,5 @@ p.equals = function(uri) {
return true;
};

(typeof module !== 'undefined' && module.exports
? module.exports = URI
: window.URI = URI
);

})();
return URI;
}));
27 changes: 15 additions & 12 deletions src/URITemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
* GPL v3 http://opensource.org/licenses/GPL-3.0
*
*/
(function(undefined) {
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('./URI'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['./URI'], factory);
} else {
// Browser globals (root is window)
root.URITemplate = factory(root.URI);
}
}(this, function (URI) {
"use strict";

var hasOwn = Object.prototype.hasOwnProperty,
_use_module = typeof module !== "undefined" && module.exports,
_load_module = function(module) {
return _use_module ? require('./' + module) : window[module];
},
URI = _load_module('URI'),
URITemplate = function(expression) {
// serve from cache where possible
if (URITemplate._cache[expression]) {
Expand Down Expand Up @@ -470,9 +477,5 @@ URI.expand = function(expression, data) {
return new URI(expansion);
};

(typeof module !== 'undefined' && module.exports
? module.exports = URITemplate
: window.URITemplate = URITemplate
);

})();
return URITemplate;
}));
24 changes: 17 additions & 7 deletions src/jquery.URI.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@
*
*/

(function($, undefined){
(function (root, factory) {
// https://github.com/umdjs/umd/blob/master/returnExports.js
if (typeof exports === 'object') {
// Node
module.exports = factory(require('jquery', './URI'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery', './URI'], factory);
} else {
// Browser globals (root is window)
factory(root.jQuery, root.URI);
}
}(this, function ($, URI) {
"use strict";

var URI = typeof module !== "undefined" && module.exports
? require('./URIjs')
: window.URI;

var comparable = {};
var compare = {
// equals
Expand Down Expand Up @@ -224,6 +232,8 @@ if ($.expr.createPseudo) {
};
}

jQuery.expr[":"].uri = uriSizzle;
$.expr[":"].uri = uriSizzle;

})(jQuery);
// extending existing object rather than defining something new
return {};
}));

0 comments on commit 7039230

Please sign in to comment.