From 7761d116f1c3dcc0680983d845988f46fcc6cc42 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Tue, 22 Mar 2016 15:19:16 -0400 Subject: [PATCH] chore(all): prepare release 1.0.0-beta.1.2.0 --- bower.json | 2 +- dist/amd/aurelia-path.js | 27 ++- dist/aurelia-path.js | 2 +- dist/commonjs/aurelia-path.js | 23 ++- dist/{es6 => es2015}/aurelia-path.d.ts | 0 dist/{es6 => es2015}/aurelia-path.js | 104 ++-------- dist/system/aurelia-path.js | 275 +++++++++++++------------ doc/CHANGELOG.md | 4 + package.json | 2 +- 9 files changed, 199 insertions(+), 240 deletions(-) rename dist/{es6 => es2015}/aurelia-path.d.ts (100%) rename dist/{es6 => es2015}/aurelia-path.js (55%) diff --git a/bower.json b/bower.json index 19515a9..1ebd25d 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-path", - "version": "1.0.0-beta.1.1.1", + "version": "1.0.0-beta.1.2.0", "description": "Utilities for path manipulation.", "keywords": [ "aurelia", diff --git a/dist/amd/aurelia-path.js b/dist/amd/aurelia-path.js index 390e951..2967751 100644 --- a/dist/amd/aurelia-path.js +++ b/dist/amd/aurelia-path.js @@ -1,11 +1,20 @@ define(['exports'], function (exports) { 'use strict'; - exports.__esModule = true; + Object.defineProperty(exports, "__esModule", { + value: true + }); exports.relativeToFile = relativeToFile; exports.join = join; exports.buildQueryString = buildQueryString; exports.parseQueryString = parseQueryString; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + }; + function trimDots(ary) { for (var i = 0; i < ary.length; ++i) { var part = ary[i]; @@ -50,7 +59,7 @@ define(['exports'], function (exports) { var scheme = schemeMatch && schemeMatch.length > 0 ? schemeMatch[1] : ''; path1 = path1.substr(scheme.length); - var urlPrefix = undefined; + var urlPrefix = void 0; if (path1.indexOf('///') === 0 && scheme === 'file:') { urlPrefix = '///'; } else if (path1.indexOf('//') === 0) { @@ -77,13 +86,13 @@ define(['exports'], function (exports) { } } - for (var i = 0, ii = url2.length; i < ii; ++i) { - if (url2[i] === '..') { + for (var _i = 0, _ii = url2.length; _i < _ii; ++_i) { + if (url2[_i] === '..') { url3.pop(); - } else if (url2[i] === '.' || url2[i] === '') { + } else if (url2[_i] === '.' || url2[_i] === '') { continue; } else { - url3.push(url2[i]); + url3.push(url2[_i]); } } @@ -102,10 +111,10 @@ define(['exports'], function (exports) { } if (Array.isArray(value)) { for (var i = 0, l = value.length; i < l; i++) { - var arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']'; + var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']'; result = result.concat(buildParam(arrayKey, value[i])); } - } else if (typeof value === 'object') { + } else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { for (var propertyName in value) { result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName])); } @@ -148,7 +157,7 @@ define(['exports'], function (exports) { for (var j = 0; j <= keysLastIndex; j++) { var key = keys[j] === '' ? currentParams.length : keys[j]; if (j < keysLastIndex) { - currentParams = currentParams[key] = currentParams[key] || (keys[j + 1] ? {} : []); + currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []); } else { currentParams = currentParams[key] = value; } diff --git a/dist/aurelia-path.js b/dist/aurelia-path.js index 936e505..fb7d7e9 100644 --- a/dist/aurelia-path.js +++ b/dist/aurelia-path.js @@ -192,7 +192,7 @@ function parseComplexParam(queryParams: Object, keys: Object, value: any): void for (let j = 0; j <= keysLastIndex; j++) { let key = keys[j] === '' ? currentParams.length : keys[j]; if (j < keysLastIndex) { - currentParams = currentParams[key] = currentParams[key] || (keys[j + 1] ? {} : []); + currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []); } else { currentParams = currentParams[key] = value; } diff --git a/dist/commonjs/aurelia-path.js b/dist/commonjs/aurelia-path.js index 15fd06f..a526f09 100644 --- a/dist/commonjs/aurelia-path.js +++ b/dist/commonjs/aurelia-path.js @@ -1,6 +1,11 @@ 'use strict'; -exports.__esModule = true; +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; + exports.relativeToFile = relativeToFile; exports.join = join; exports.buildQueryString = buildQueryString; @@ -49,7 +54,7 @@ function join(path1, path2) { var scheme = schemeMatch && schemeMatch.length > 0 ? schemeMatch[1] : ''; path1 = path1.substr(scheme.length); - var urlPrefix = undefined; + var urlPrefix = void 0; if (path1.indexOf('///') === 0 && scheme === 'file:') { urlPrefix = '///'; } else if (path1.indexOf('//') === 0) { @@ -76,13 +81,13 @@ function join(path1, path2) { } } - for (var i = 0, ii = url2.length; i < ii; ++i) { - if (url2[i] === '..') { + for (var _i = 0, _ii = url2.length; _i < _ii; ++_i) { + if (url2[_i] === '..') { url3.pop(); - } else if (url2[i] === '.' || url2[i] === '') { + } else if (url2[_i] === '.' || url2[_i] === '') { continue; } else { - url3.push(url2[i]); + url3.push(url2[_i]); } } @@ -101,10 +106,10 @@ function buildParam(key, value) { } if (Array.isArray(value)) { for (var i = 0, l = value.length; i < l; i++) { - var arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']'; + var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']'; result = result.concat(buildParam(arrayKey, value[i])); } - } else if (typeof value === 'object') { + } else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { for (var propertyName in value) { result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName])); } @@ -147,7 +152,7 @@ function parseComplexParam(queryParams, keys, value) { for (var j = 0; j <= keysLastIndex; j++) { var key = keys[j] === '' ? currentParams.length : keys[j]; if (j < keysLastIndex) { - currentParams = currentParams[key] = currentParams[key] || (keys[j + 1] ? {} : []); + currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []); } else { currentParams = currentParams[key] = value; } diff --git a/dist/es6/aurelia-path.d.ts b/dist/es2015/aurelia-path.d.ts similarity index 100% rename from dist/es6/aurelia-path.d.ts rename to dist/es2015/aurelia-path.d.ts diff --git a/dist/es6/aurelia-path.js b/dist/es2015/aurelia-path.js similarity index 55% rename from dist/es6/aurelia-path.js rename to dist/es2015/aurelia-path.js index 936e505..4c0d474 100644 --- a/dist/es6/aurelia-path.js +++ b/dist/es2015/aurelia-path.js @@ -1,41 +1,25 @@ -function trimDots(ary: string[]): void { +function trimDots(ary) { for (let i = 0; i < ary.length; ++i) { let 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] === '..') { + if (i === 0 || i === 1 && ary[2] === '..' || ary[i - 1] === '..') { continue; } else if (i > 0) { ary.splice(i - 1, 2); i -= 2; } } - }} + } +} -/** -* Calcualtes a path relative to a file. -* -* @param name The relative path. -* @param file The file path. -* @return The calcualted path. -*/ -export function relativeToFile(name: string, file: string): string { +export function relativeToFile(name, file) { let fileParts = file && file.split('/'); let nameParts = name.trim().split('/'); if (nameParts[0].charAt(0) === '.' && fileParts) { - //Convert file to array, and lop off the last part, - //so that . matches that 'directory' and not name of the file's - //module. For instance, file of 'one/two/three', maps to - //'one/two/three.js', but we want the directory, 'one/two' for - //this normalization. let normalizedBaseParts = fileParts.slice(0, fileParts.length - 1); nameParts.unshift(...normalizedBaseParts); } @@ -45,14 +29,7 @@ export function relativeToFile(name: string, file: string): string { return nameParts.join('/'); } -/** -* Joins two paths. -* -* @param path1 The first path. -* @param path2 The second path. -* @return The joined path. -*/ -export function join(path1: string, path2: string): string { +export function join(path1, path2) { if (!path1) { return path2; } @@ -62,7 +39,7 @@ export function join(path1: string, path2: string): string { } let schemeMatch = path1.match(/^([^/]*?:)\//); - let scheme = (schemeMatch && schemeMatch.length > 0) ? schemeMatch[1] : ''; + let scheme = schemeMatch && schemeMatch.length > 0 ? schemeMatch[1] : ''; path1 = path1.substr(scheme.length); let urlPrefix; @@ -107,14 +84,8 @@ export function join(path1: string, path2: string): string { let encode = encodeURIComponent; let encodeKey = k => encode(k).replace('%24', '$'); -/** -* Recursively builds part of query string for parameter. -* -* @param key Parameter name for query string. -* @param value Parameter value to deserialize. -* @return Array with serialized parameter(s) -*/ -function buildParam(key: string, value: any): Array { + +function buildParam(key, value) { let result = []; if (value === null || value === undefined) { return result; @@ -124,23 +95,17 @@ function buildParam(key: string, value: any): Array { let arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']'; result = result.concat(buildParam(arrayKey, value[i])); } - } else if (typeof (value) === 'object') { + } else if (typeof value === 'object') { for (let propertyName in value) { result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName])); } } else { - result.push(`${encodeKey(key) }=${encode(value) }`); + result.push(`${ encodeKey(key) }=${ encode(value) }`); } return result; } -/** -* Generate a query string from an object. -* -* @param params Object containing the keys and values to be used. -* @returns The generated query string, excluding leading '?'. -*/ -export function buildQueryString(params: Object): string { +export function buildQueryString(params) { let pairs = []; let keys = Object.keys(params || {}).sort(); for (let i = 0, len = keys.length; i < len; i++) { @@ -155,58 +120,32 @@ export function buildQueryString(params: Object): string { return pairs.join('&'); } -/** -* Process parameter that was recognized as scalar param (primitive value or shallow array). -* -* @param existedParam Object with previously parsed values for specified key. -* @param value Parameter value to append. -* @param isPrimitive If true and parameter value already specified - method overwrites it. If false - transofrm parameter to array and append new value to it. -* @returns Initial primitive value or transformed existedParam if parameter was recognized as an array. -*/ -function processScalarParam(existedParam: Object, value: Object, isPrimitive: boolean): Object { +function processScalarParam(existedParam, value, isPrimitive) { if (Array.isArray(existedParam)) { - // value is already an array, so push on the next value. existedParam.push(value); return existedParam; } if (existedParam !== undefined) { - // value isn't an array, but since a second value has been specified, - // convert value into an array. return isPrimitive ? value : [existedParam, value]; } - // value is a scalar. + return value; } -/** -* Sequentially process parameter that was recognized as complex value (object or array). -* For each keys part, if the current level is undefined create an -* object or array based on the type of the next keys part. -* -* @param queryParams root-level result object. -* @param keys Collection of keys related to this parameter. -* @param value Parameter value to append. -*/ -function parseComplexParam(queryParams: Object, keys: Object, value: any): void { + +function parseComplexParam(queryParams, keys, value) { let currentParams = queryParams; let keysLastIndex = keys.length - 1; for (let j = 0; j <= keysLastIndex; j++) { let key = keys[j] === '' ? currentParams.length : keys[j]; if (j < keysLastIndex) { - currentParams = currentParams[key] = currentParams[key] || (keys[j + 1] ? {} : []); + currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []); } else { currentParams = currentParams[key] = value; } } } - -/** -* Parse a query string. -* -* @param queryString The query string to parse. -* @returns Object with keys and values mapped from the query string. -*/ -export function parseQueryString(queryString: string): Object { +export function parseQueryString(queryString) { let queryParams = {}; if (!queryString || typeof queryString !== 'string') { return queryParams; @@ -225,13 +164,10 @@ export function parseQueryString(queryString: string): Object { if (!key) { continue; } - //split object key into its parts + let keys = key.split(']['); let keysLastIndex = keys.length - 1; - // If the first keys part contains [ and the last ends with ], then [] - // are correctly balanced, split key to parts - //Else it's basic key if (/\[/.test(keys[0]) && /\]$/.test(keys[keysLastIndex])) { keys[keysLastIndex] = keys[keysLastIndex].replace(/\]$/, ''); keys = keys.shift().split('[').concat(keys); @@ -253,4 +189,4 @@ export function parseQueryString(queryString: string): Object { } } return queryParams; -} +} \ No newline at end of file diff --git a/dist/system/aurelia-path.js b/dist/system/aurelia-path.js index 21e1279..e19186a 100644 --- a/dist/system/aurelia-path.js +++ b/dist/system/aurelia-path.js @@ -1,15 +1,7 @@ -System.register([], function (_export) { - 'use strict'; +'use strict'; - var encode, encodeKey; - - _export('relativeToFile', relativeToFile); - - _export('join', join); - - _export('buildQueryString', buildQueryString); - - _export('parseQueryString', parseQueryString); +System.register([], function (_export, _context) { + var _typeof, encode, encodeKey; function trimDots(ary) { for (var i = 0; i < ary.length; ++i) { @@ -28,73 +20,6 @@ System.register([], function (_export) { } } - function relativeToFile(name, file) { - var fileParts = file && file.split('/'); - var nameParts = name.trim().split('/'); - - if (nameParts[0].charAt(0) === '.' && fileParts) { - var normalizedBaseParts = fileParts.slice(0, fileParts.length - 1); - nameParts.unshift.apply(nameParts, normalizedBaseParts); - } - - trimDots(nameParts); - - return nameParts.join('/'); - } - - function join(path1, path2) { - if (!path1) { - return path2; - } - - if (!path2) { - return path1; - } - - var schemeMatch = path1.match(/^([^/]*?:)\//); - var scheme = schemeMatch && schemeMatch.length > 0 ? schemeMatch[1] : ''; - path1 = path1.substr(scheme.length); - - var urlPrefix = undefined; - if (path1.indexOf('///') === 0 && scheme === 'file:') { - urlPrefix = '///'; - } else if (path1.indexOf('//') === 0) { - urlPrefix = '//'; - } else if (path1.indexOf('/') === 0) { - urlPrefix = '/'; - } else { - urlPrefix = ''; - } - - var trailingSlash = path2.slice(-1) === '/' ? '/' : ''; - - var url1 = path1.split('/'); - var url2 = path2.split('/'); - var url3 = []; - - for (var i = 0, ii = url1.length; i < ii; ++i) { - if (url1[i] === '..') { - url3.pop(); - } else if (url1[i] === '.' || url1[i] === '') { - continue; - } else { - url3.push(url1[i]); - } - } - - for (var i = 0, ii = url2.length; i < ii; ++i) { - if (url2[i] === '..') { - url3.pop(); - } else if (url2[i] === '.' || url2[i] === '') { - continue; - } else { - url3.push(url2[i]); - } - } - - return scheme + urlPrefix + url3.join('/') + trailingSlash; - } - function buildParam(key, value) { var result = []; if (value === null || value === undefined) { @@ -102,10 +27,10 @@ System.register([], function (_export) { } if (Array.isArray(value)) { for (var i = 0, l = value.length; i < l; i++) { - var arrayKey = key + '[' + (typeof value[i] === 'object' && value[i] !== null ? i : '') + ']'; + var arrayKey = key + '[' + (_typeof(value[i]) === 'object' && value[i] !== null ? i : '') + ']'; result = result.concat(buildParam(arrayKey, value[i])); } - } else if (typeof value === 'object') { + } else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { for (var propertyName in value) { result = result.concat(buildParam(key + '[' + propertyName + ']', value[propertyName])); } @@ -115,21 +40,6 @@ System.register([], function (_export) { return result; } - function buildQueryString(params) { - var pairs = []; - var keys = Object.keys(params || {}).sort(); - for (var i = 0, len = keys.length; i < len; i++) { - var key = keys[i]; - pairs = pairs.concat(buildParam(key, params[key])); - } - - if (pairs.length === 0) { - return ''; - } - - return pairs.join('&'); - } - function processScalarParam(existedParam, value, isPrimitive) { if (Array.isArray(existedParam)) { existedParam.push(value); @@ -148,67 +58,162 @@ System.register([], function (_export) { for (var j = 0; j <= keysLastIndex; j++) { var key = keys[j] === '' ? currentParams.length : keys[j]; if (j < keysLastIndex) { - currentParams = currentParams[key] = currentParams[key] || (keys[j + 1] ? {} : []); + currentParams = currentParams[key] = currentParams[key] || (isNaN(keys[j + 1]) ? {} : []); } else { currentParams = currentParams[key] = value; } } } - function parseQueryString(queryString) { - var queryParams = {}; - if (!queryString || typeof queryString !== 'string') { - return queryParams; - } + return { + setters: [], + execute: function () { + _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + }; + function relativeToFile(name, file) { + var fileParts = file && file.split('/'); + var nameParts = name.trim().split('/'); - var query = queryString; - if (query.charAt(0) === '?') { - query = query.substr(1); - } + if (nameParts[0].charAt(0) === '.' && fileParts) { + var normalizedBaseParts = fileParts.slice(0, fileParts.length - 1); + nameParts.unshift.apply(nameParts, normalizedBaseParts); + } - var pairs = query.replace(/\+/g, ' ').split('&'); - for (var i = 0; i < pairs.length; i++) { - var pair = pairs[i].split('='); - var key = decodeURIComponent(pair[0]); - var isPrimitive = false; - if (!key) { - continue; + trimDots(nameParts); + + return nameParts.join('/'); } - var keys = key.split(']['); - var keysLastIndex = keys.length - 1; + _export('relativeToFile', relativeToFile); - if (/\[/.test(keys[0]) && /\]$/.test(keys[keysLastIndex])) { - keys[keysLastIndex] = keys[keysLastIndex].replace(/\]$/, ''); - keys = keys.shift().split('[').concat(keys); - keysLastIndex = keys.length - 1; - } else { - isPrimitive = true; - keysLastIndex = 0; - } + function join(path1, path2) { + if (!path1) { + return path2; + } - if (pair.length === 2) { - var value = pair[1] ? decodeURIComponent(pair[1]) : ''; - if (keysLastIndex) { - parseComplexParam(queryParams, keys, value); + if (!path2) { + return path1; + } + + var schemeMatch = path1.match(/^([^/]*?:)\//); + var scheme = schemeMatch && schemeMatch.length > 0 ? schemeMatch[1] : ''; + path1 = path1.substr(scheme.length); + + var urlPrefix = void 0; + if (path1.indexOf('///') === 0 && scheme === 'file:') { + urlPrefix = '///'; + } else if (path1.indexOf('//') === 0) { + urlPrefix = '//'; + } else if (path1.indexOf('/') === 0) { + urlPrefix = '/'; } else { - queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive); + urlPrefix = ''; } - } else { - queryParams[key] = true; + + var trailingSlash = path2.slice(-1) === '/' ? '/' : ''; + + var url1 = path1.split('/'); + var url2 = path2.split('/'); + var url3 = []; + + for (var i = 0, ii = url1.length; i < ii; ++i) { + if (url1[i] === '..') { + url3.pop(); + } else if (url1[i] === '.' || url1[i] === '') { + continue; + } else { + url3.push(url1[i]); + } + } + + for (var _i = 0, _ii = url2.length; _i < _ii; ++_i) { + if (url2[_i] === '..') { + url3.pop(); + } else if (url2[_i] === '.' || url2[_i] === '') { + continue; + } else { + url3.push(url2[_i]); + } + } + + return scheme + urlPrefix + url3.join('/') + trailingSlash; } - } - return queryParams; - } - return { - setters: [], - execute: function () { + _export('join', join); + encode = encodeURIComponent; encodeKey = function encodeKey(k) { return encode(k).replace('%24', '$'); }; + + function buildQueryString(params) { + var pairs = []; + var keys = Object.keys(params || {}).sort(); + for (var i = 0, len = keys.length; i < len; i++) { + var key = keys[i]; + pairs = pairs.concat(buildParam(key, params[key])); + } + + if (pairs.length === 0) { + return ''; + } + + return pairs.join('&'); + } + + _export('buildQueryString', buildQueryString); + + function parseQueryString(queryString) { + var queryParams = {}; + if (!queryString || typeof queryString !== 'string') { + return queryParams; + } + + var query = queryString; + if (query.charAt(0) === '?') { + query = query.substr(1); + } + + var pairs = query.replace(/\+/g, ' ').split('&'); + for (var i = 0; i < pairs.length; i++) { + var pair = pairs[i].split('='); + var key = decodeURIComponent(pair[0]); + var isPrimitive = false; + if (!key) { + continue; + } + + var keys = key.split(']['); + var keysLastIndex = keys.length - 1; + + if (/\[/.test(keys[0]) && /\]$/.test(keys[keysLastIndex])) { + keys[keysLastIndex] = keys[keysLastIndex].replace(/\]$/, ''); + keys = keys.shift().split('[').concat(keys); + keysLastIndex = keys.length - 1; + } else { + isPrimitive = true; + keysLastIndex = 0; + } + + if (pair.length === 2) { + var value = pair[1] ? decodeURIComponent(pair[1]) : ''; + if (keysLastIndex) { + parseComplexParam(queryParams, keys, value); + } else { + queryParams[key] = processScalarParam(queryParams[key], value, isPrimitive); + } + } else { + queryParams[key] = true; + } + } + return queryParams; + } + + _export('parseQueryString', parseQueryString); } }; }); \ No newline at end of file diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 2f0e9c6..58c9360 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,7 @@ +### 1.0.0-beta.1.2.0 (2016-03-22) + +* Update to Babel 6 + ### 1.0.0-beta.1.1.1 (2016-03-01) diff --git a/package.json b/package.json index c3b970c..845bc00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-path", - "version": "1.0.0-beta.1.1.1", + "version": "1.0.0-beta.1.2.0", "description": "Utilities for path manipulation.", "keywords": [ "aurelia",