Skip to content

Commit

Permalink
default export changed to named export
Browse files Browse the repository at this point in the history
  • Loading branch information
worka committed Mar 5, 2020
1 parent eaa6bae commit addfe72
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 46 deletions.
43 changes: 25 additions & 18 deletions dist/url.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function(global, factory) {
typeof exports === 'object' && typeof module !== 'undefined'
? (module.exports = factory())
? factory(exports)
: typeof define === 'function' && define.amd
? define(factory)
: ((global = global || self), (global.jcurl = factory()));
})(this, function() {
? define(['exports'], factory)
: ((global = global || self), factory((global.jcurl = {})));
})(this, function(exports) {
'use strict';

/**
Expand Down Expand Up @@ -336,18 +336,25 @@

return url;
}

var url = {
getParams: getParams,
getParamsExtended: getParamsExtended,
addParams: addParams,
addParamsExtended: addParamsExtended,
// short aliases
get: getParams,
getExt: getParamsExtended,
add: addParams,
addExt: addParamsExtended
};

return url;
// getParams,
// getParamsExtended,
// addParams,
// addParamsExtended,
// // short aliases
// get: getParams,
// getExt: getParamsExtended,
// add: addParams,
// addExt: addParamsExtended
// };

exports.add = addParams;
exports.addExt = addParamsExtended;
exports.addParams = addParams;
exports.addParamsExtended = addParamsExtended;
exports.get = getParams;
exports.getExt = getParamsExtended;
exports.getParams = getParams;
exports.getParamsExtended = getParamsExtended;

Object.defineProperty(exports, '__esModule', { value: true });
});
2 changes: 1 addition & 1 deletion dist/url.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@ function addParamsExtended(url, newParams) {
return url;
}

export default {
export {
getParams,
getParamsExtended,
addParams,
addParamsExtended,
// short aliases
get: getParams,
getExt: getParamsExtended,
add: addParams,
addExt: addParamsExtended
getParams as get,
getParamsExtended as getExt,
addParams as add,
addParamsExtended as addExt
};

// export default {
// getParams,
// getParamsExtended,
// addParams,
// addParamsExtended,
// // short aliases
// get: getParams,
// getExt: getParamsExtended,
// add: addParams,
// addExt: addParamsExtended
// };
44 changes: 22 additions & 22 deletions src/url.test.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import jcurl from './url';
import { getParams, getParamsExtended, addParams, addParamsExtended } from './url';

describe('GET', () => {
test('getParams()', () => {
expect(jcurl.getParams('example.com')).toEqual({});
expect(jcurl.getParams('example.com?bar=1&foo')).toEqual({ bar: '1', foo: '' });
expect(jcurl.getParams('example.com?bar=1&bar=2')).toEqual({ bar: '2' });
expect(jcurl.getParams('example.com?bar[]=1&bar[]=2')).toEqual({ bar: ['1', '2'] });
expect(jcurl.getParams('example.com?bar=1&bar[]=2')).toEqual({ bar: ['2'] });
expect(getParams('example.com')).toEqual({});
expect(getParams('example.com?bar=1&foo')).toEqual({ bar: '1', foo: '' });
expect(getParams('example.com?bar=1&bar=2')).toEqual({ bar: '2' });
expect(getParams('example.com?bar[]=1&bar[]=2')).toEqual({ bar: ['1', '2'] });
expect(getParams('example.com?bar=1&bar[]=2')).toEqual({ bar: ['2'] });
});

test('getParamsExtended()', () => {
expect(jcurl.getParamsExtended('example.com?bar[t]=1&bar[j]=2')).toEqual({ bar: { t: '1', j: '2' } });
expect(jcurl.getParamsExtended('example.com?bar[t]=1&bar[j]=2&bar[j]=3')).toEqual({ bar: { t: '1', j: '3' } });
expect(jcurl.getParamsExtended('example.com?b[t]=1&b[j]=2&b[j][g]=3'))
expect(getParamsExtended('example.com?bar[t]=1&bar[j]=2')).toEqual({ bar: { t: '1', j: '2' } });
expect(getParamsExtended('example.com?bar[t]=1&bar[j]=2&bar[j]=3')).toEqual({ bar: { t: '1', j: '3' } });
expect(getParamsExtended('example.com?b[t]=1&b[j]=2&b[j][g]=3'))
.toEqual({ b: { t: '1', j: { g: '3' } } });
expect(jcurl.getParamsExtended('example.com?bar=-1&bar[]=0&bar[tr]=1&bar[j]=2&bar[foo][too][poo]=3&bar[]=4&bar[foo][too][hoo]=5'))
expect(getParamsExtended('example.com?bar=-1&bar[]=0&bar[tr]=1&bar[j]=2&bar[foo][too][poo]=3&bar[]=4&bar[foo][too][hoo]=5'))
.toEqual({ bar: { '1': '0', tr: '1', j: '2', foo: { too: { poo: '3', hoo: '5' } }, '5': '4' } });
});
});

describe('ADD', () => {
test('addParams()', () => {
expect(jcurl.addParams('example.com', { bar: 1 })).toBe('example.com?bar=1');
expect(jcurl.addParams('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
expect(jcurl.addParams('example.com?bar=1&foo', { bar: 2 })).toBe('example.com?bar=2&foo=');
expect(jcurl.addParams('example.com?bar=1&foo', { bar: 2, foo: 2 })).toBe('example.com?bar=2&foo=2');
expect(jcurl.addParams('example.com?bar=1', { bar: [2, 3] })).toBe('example.com?bar[]=2&bar[]=3');
expect(jcurl.addParams('example.com?bar=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=2&bar[]=3&bar[]=4');
expect(jcurl.addParams('example.com?bar=1&bar=2', { bar: [3, 4] })).toBe('example.com?bar[]=3&bar[]=4');
expect(jcurl.addParams('example.com?bar[]=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=1&bar[]=2&bar[]=3&bar[]=4');
expect(addParams('example.com', { bar: 1 })).toBe('example.com?bar=1');
expect(addParams('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
expect(addParams('example.com?bar=1&foo', { bar: 2 })).toBe('example.com?bar=2&foo=');
expect(addParams('example.com?bar=1&foo', { bar: 2, foo: 2 })).toBe('example.com?bar=2&foo=2');
expect(addParams('example.com?bar=1', { bar: [2, 3] })).toBe('example.com?bar[]=2&bar[]=3');
expect(addParams('example.com?bar=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=2&bar[]=3&bar[]=4');
expect(addParams('example.com?bar=1&bar=2', { bar: [3, 4] })).toBe('example.com?bar[]=3&bar[]=4');
expect(addParams('example.com?bar[]=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=1&bar[]=2&bar[]=3&bar[]=4');
});

test('addParamsExtended()', () => {
expect(jcurl.addParamsExtended('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
expect(addParamsExtended('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
/**
* BUG
*/
// expect(jcurl.addParamsExtended('example.com?bar[foo]=test&bar[joo]=2', { bar: { foo: 'new', too: 5 } }))
// expect(addParamsExtended('example.com?bar[foo]=test&bar[joo]=2', { bar: { foo: 'new', too: 5 } }))
// .toBe('example.com?bar[foo]=new&bar[joo]=2&bar[too]=5');
expect(jcurl.addParamsExtended('example.com', { bar: { foo: 'test', joo: 2 } }))
expect(addParamsExtended('example.com', { bar: { foo: 'test', joo: 2 } }))
.toBe('example.com?bar[foo]=test&bar[joo]=2');
expect(jcurl.addParamsExtended('example.com', {
expect(addParamsExtended('example.com', {
f1: { f11: 1, f12: 2, f13: 3 }, f2: 4, f3: { f31: { f311: 6, f312: { f3121: 9 } }, f32: { f321: 2 } },
f4: { f41: 3, f42: { f421: 2 } }, f5: [2, 4]
})).toBe('example.com?f1[f11]=1&f1[f12]=2&f1[f13]=3&f2=4&f3[f31][f311]=6&f3[f31][f312][f3121]=9&f3[f32][f321]=2&f4[f41]=3&f4[f42][f421]=2&f5[0]=2&f5[1]=4');
Expand Down

0 comments on commit addfe72

Please sign in to comment.