From d1e83ffd2e7259c571829c7fafa6f71cbb21d70c Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 16 Dec 2014 16:49:21 -0500 Subject: [PATCH] chore(*): prepare release 0.2.0 --- bower.json | 2 +- dist/amd/index.js | 46 +++++++++++++++++++---------- dist/commonjs/index.js | 46 +++++++++++++++++++---------- dist/es6/index.js | 67 +++++++++++++++++++++++++++++------------- doc/CHANGELOG.md | 7 +++++ package.json | 2 +- 6 files changed, 118 insertions(+), 52 deletions(-) create mode 100644 doc/CHANGELOG.md diff --git a/bower.json b/bower.json index b503e89..4c9a9f4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-path", - "version": "0.1.0", + "version": "0.2.0", "keywords": [ "aurelia", "path" diff --git a/dist/amd/index.js b/dist/amd/index.js index 6512a62..34f11bb 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -2,6 +2,25 @@ define(["exports"], function (exports) { "use strict"; exports.normalize = normalize; + exports.join = join; + function trimDots(ary) { + var i, part; + for (i = 0; i < ary.length; i++) { + part = ary[i]; + if (part === ".") { + ary.splice(i, 1); + i -= 1; + } else if (part === "..") { + if (i === 0 || (i == 1 && ary[2] === "..") || ary[i - 1] === "..") { + continue; + } else if (i > 0) { + ary.splice(i - 1, 2); + i -= 2; + } + } + } + } + function normalize(name, baseName) { var lastIndex, normalizedBaseParts, baseParts = (baseName && baseName.split("/")); @@ -18,21 +37,18 @@ define(["exports"], function (exports) { return name.join("/"); } - function trimDots(ary) { - var i, part; - for (i = 0; i < ary.length; i++) { - part = ary[i]; - if (part === ".") { - ary.splice(i, 1); - i -= 1; - } else if (part === "..") { - if (i === 0 || (i == 1 && ary[2] === "..") || ary[i - 1] === "..") { - continue; - } else if (i > 0) { - ary.splice(i - 1, 2); - i -= 2; - } - } + function join() { + var parts = []; + for (var i = 0, l = arguments.length; i < l; i++) { + parts = parts.concat(arguments[i].split("/")); + } + var newParts = []; + for (i = 0, l = parts.length; i < l; i++) { + var part = parts[i]; + if (!part || part === ".") continue; + if (part === "..") newParts.pop();else newParts.push(part); } + if (parts[0] === "") newParts.unshift(""); + return newParts.join("/") || (newParts.length ? "/" : "."); } }); \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index c34b2a7..3f1dbc3 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -1,6 +1,25 @@ "use strict"; exports.normalize = normalize; +exports.join = join; +function trimDots(ary) { + var i, part; + for (i = 0; i < ary.length; i++) { + part = ary[i]; + if (part === ".") { + ary.splice(i, 1); + i -= 1; + } else if (part === "..") { + if (i === 0 || (i == 1 && ary[2] === "..") || ary[i - 1] === "..") { + continue; + } else if (i > 0) { + ary.splice(i - 1, 2); + i -= 2; + } + } + } +} + function normalize(name, baseName) { var lastIndex, normalizedBaseParts, baseParts = (baseName && baseName.split("/")); @@ -17,20 +36,17 @@ function normalize(name, baseName) { return name.join("/"); } -function trimDots(ary) { - var i, part; - for (i = 0; i < ary.length; i++) { - part = ary[i]; - if (part === ".") { - ary.splice(i, 1); - i -= 1; - } else if (part === "..") { - if (i === 0 || (i == 1 && ary[2] === "..") || ary[i - 1] === "..") { - continue; - } else if (i > 0) { - ary.splice(i - 1, 2); - i -= 2; - } - } +function join() { + var parts = []; + for (var i = 0, l = arguments.length; i < l; i++) { + parts = parts.concat(arguments[i].split("/")); + } + var newParts = []; + for (i = 0, l = parts.length; i < l; i++) { + var part = parts[i]; + if (!part || part === ".") continue; + if (part === "..") newParts.pop();else newParts.push(part); } + if (parts[0] === "") newParts.unshift(""); + return newParts.join("/") || (newParts.length ? "/" : "."); } \ No newline at end of file diff --git a/dist/es6/index.js b/dist/es6/index.js index 4f6ff6f..4a512c5 100644 --- a/dist/es6/index.js +++ b/dist/es6/index.js @@ -1,3 +1,26 @@ +function trimDots(ary) { + var i, part; + for (i = 0; i < ary.length; i++) { + part = ary[i]; + if (part === '.') { + ary.splice(i, 1); + i -= 1; + } else if (part === '..') { + // If at the start, or previous value is still .., + // keep them so that when converted to a path it may + // still work when converted to a path, even though + // as an ID it is less than ideal. In larger point + // releases, may be better to just kick out an error. + if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') { + continue; + } else if (i > 0) { + ary.splice(i - 1, 2); + i -= 2; + } + } + } +} + export function normalize(name, baseName){ var lastIndex, normalizedBaseParts, @@ -21,25 +44,29 @@ export function normalize(name, baseName){ return name.join('/'); } -function trimDots(ary) { - var i, part; - for (i = 0; i < ary.length; i++) { - part = ary[i]; - if (part === '.') { - ary.splice(i, 1); - i -= 1; - } else if (part === '..') { - // If at the start, or previous value is still .., - // keep them so that when converted to a path it may - // still work when converted to a path, even though - // as an ID it is less than ideal. In larger point - // releases, may be better to just kick out an error. - if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') { - continue; - } else if (i > 0) { - ary.splice(i - 1, 2); - i -= 2; - } - } +// Joins path segments. Preserves initial "/" and resolves ".." and "." +// Does not support using ".." to go above/outside the root. +// This means that join("foo", "../../bar") will not resolve to "../bar" +export function join(/* path segments */) { + // Split the inputs into a list of path commands. + var parts = []; + for (var i = 0, l = arguments.length; i < l; i++) { + parts = parts.concat(arguments[i].split("/")); + } + // Interpret the path commands to get the new resolved path. + var newParts = []; + for (i = 0, l = parts.length; i < l; i++) { + var part = parts[i]; + // Remove leading and trailing slashes + // Also remove "." segments + if (!part || part === ".") continue; + // Interpret ".." to pop the last segment + if (part === "..") newParts.pop(); + // Push new path segments. + else newParts.push(part); } + // Preserve the initial slash if there was one. + if (parts[0] === "") newParts.unshift(""); + // Turn back into a single string path. + return newParts.join("/") || (newParts.length ? "/" : "."); } \ No newline at end of file diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md new file mode 100644 index 0000000..35e34e8 --- /dev/null +++ b/doc/CHANGELOG.md @@ -0,0 +1,7 @@ +## 0.2.0 (2014-12-16) + + +#### Features + +* **join:** add a utility for joining paths ([9342f179](http://github.com/aurelia/path/commit/9342f179e548847f6c27d7e8a5b7fbb275f9c5b2)) + diff --git a/package.json b/package.json index 134c8b2..f6fd79b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-path", - "version": "0.1.0", + "version": "0.2.0", "description": "Utilities for path manipulation.", "keywords": [ "aurelia",