Skip to content

Commit

Permalink
chore(all): prepare release 1.0.0-beta.1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Mar 22, 2016
1 parent e6614d7 commit 7761d11
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 240 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 18 additions & 9 deletions dist/amd/aurelia-path.js
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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]);
}
}

Expand All @@ -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]));
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/aurelia-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 14 additions & 9 deletions dist/commonjs/aurelia-path.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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]);
}
}

Expand All @@ -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]));
}
Expand Down Expand Up @@ -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;
}
Expand Down
File renamed without changes.
104 changes: 20 additions & 84 deletions dist/es6/aurelia-path.js → dist/es2015/aurelia-path.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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<string> {

function buildParam(key, value) {
let result = [];
if (value === null || value === undefined) {
return result;
Expand All @@ -124,23 +95,17 @@ function buildParam(key: string, value: any): Array<string> {
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++) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -253,4 +189,4 @@ export function parseQueryString(queryString: string): Object {
}
}
return queryParams;
}
}
Loading

0 comments on commit 7761d11

Please sign in to comment.