Skip to content

Commit addfe72

Browse files
committed
default export changed to named export
1 parent eaa6bae commit addfe72

File tree

4 files changed

+65
-46
lines changed

4 files changed

+65
-46
lines changed

dist/url.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(function(global, factory) {
22
typeof exports === 'object' && typeof module !== 'undefined'
3-
? (module.exports = factory())
3+
? factory(exports)
44
: typeof define === 'function' && define.amd
5-
? define(factory)
6-
: ((global = global || self), (global.jcurl = factory()));
7-
})(this, function() {
5+
? define(['exports'], factory)
6+
: ((global = global || self), factory((global.jcurl = {})));
7+
})(this, function(exports) {
88
'use strict';
99

1010
/**
@@ -336,18 +336,25 @@
336336

337337
return url;
338338
}
339-
340-
var url = {
341-
getParams: getParams,
342-
getParamsExtended: getParamsExtended,
343-
addParams: addParams,
344-
addParamsExtended: addParamsExtended,
345-
// short aliases
346-
get: getParams,
347-
getExt: getParamsExtended,
348-
add: addParams,
349-
addExt: addParamsExtended
350-
};
351-
352-
return url;
339+
// getParams,
340+
// getParamsExtended,
341+
// addParams,
342+
// addParamsExtended,
343+
// // short aliases
344+
// get: getParams,
345+
// getExt: getParamsExtended,
346+
// add: addParams,
347+
// addExt: addParamsExtended
348+
// };
349+
350+
exports.add = addParams;
351+
exports.addExt = addParamsExtended;
352+
exports.addParams = addParams;
353+
exports.addParamsExtended = addParamsExtended;
354+
exports.get = getParams;
355+
exports.getExt = getParamsExtended;
356+
exports.getParams = getParams;
357+
exports.getParamsExtended = getParamsExtended;
358+
359+
Object.defineProperty(exports, '__esModule', { value: true });
353360
});

dist/url.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/url.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,26 @@ function addParamsExtended(url, newParams) {
4141
return url;
4242
}
4343

44-
export default {
44+
export {
4545
getParams,
4646
getParamsExtended,
4747
addParams,
4848
addParamsExtended,
4949
// short aliases
50-
get: getParams,
51-
getExt: getParamsExtended,
52-
add: addParams,
53-
addExt: addParamsExtended
50+
getParams as get,
51+
getParamsExtended as getExt,
52+
addParams as add,
53+
addParamsExtended as addExt
5454
};
55+
56+
// export default {
57+
// getParams,
58+
// getParamsExtended,
59+
// addParams,
60+
// addParamsExtended,
61+
// // short aliases
62+
// get: getParams,
63+
// getExt: getParamsExtended,
64+
// add: addParams,
65+
// addExt: addParamsExtended
66+
// };

src/url.test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
import jcurl from './url';
1+
import { getParams, getParamsExtended, addParams, addParamsExtended } from './url';
22

33
describe('GET', () => {
44
test('getParams()', () => {
5-
expect(jcurl.getParams('example.com')).toEqual({});
6-
expect(jcurl.getParams('example.com?bar=1&foo')).toEqual({ bar: '1', foo: '' });
7-
expect(jcurl.getParams('example.com?bar=1&bar=2')).toEqual({ bar: '2' });
8-
expect(jcurl.getParams('example.com?bar[]=1&bar[]=2')).toEqual({ bar: ['1', '2'] });
9-
expect(jcurl.getParams('example.com?bar=1&bar[]=2')).toEqual({ bar: ['2'] });
5+
expect(getParams('example.com')).toEqual({});
6+
expect(getParams('example.com?bar=1&foo')).toEqual({ bar: '1', foo: '' });
7+
expect(getParams('example.com?bar=1&bar=2')).toEqual({ bar: '2' });
8+
expect(getParams('example.com?bar[]=1&bar[]=2')).toEqual({ bar: ['1', '2'] });
9+
expect(getParams('example.com?bar=1&bar[]=2')).toEqual({ bar: ['2'] });
1010
});
1111

1212
test('getParamsExtended()', () => {
13-
expect(jcurl.getParamsExtended('example.com?bar[t]=1&bar[j]=2')).toEqual({ bar: { t: '1', j: '2' } });
14-
expect(jcurl.getParamsExtended('example.com?bar[t]=1&bar[j]=2&bar[j]=3')).toEqual({ bar: { t: '1', j: '3' } });
15-
expect(jcurl.getParamsExtended('example.com?b[t]=1&b[j]=2&b[j][g]=3'))
13+
expect(getParamsExtended('example.com?bar[t]=1&bar[j]=2')).toEqual({ bar: { t: '1', j: '2' } });
14+
expect(getParamsExtended('example.com?bar[t]=1&bar[j]=2&bar[j]=3')).toEqual({ bar: { t: '1', j: '3' } });
15+
expect(getParamsExtended('example.com?b[t]=1&b[j]=2&b[j][g]=3'))
1616
.toEqual({ b: { t: '1', j: { g: '3' } } });
17-
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'))
17+
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'))
1818
.toEqual({ bar: { '1': '0', tr: '1', j: '2', foo: { too: { poo: '3', hoo: '5' } }, '5': '4' } });
1919
});
2020
});
2121

2222
describe('ADD', () => {
2323
test('addParams()', () => {
24-
expect(jcurl.addParams('example.com', { bar: 1 })).toBe('example.com?bar=1');
25-
expect(jcurl.addParams('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
26-
expect(jcurl.addParams('example.com?bar=1&foo', { bar: 2 })).toBe('example.com?bar=2&foo=');
27-
expect(jcurl.addParams('example.com?bar=1&foo', { bar: 2, foo: 2 })).toBe('example.com?bar=2&foo=2');
28-
expect(jcurl.addParams('example.com?bar=1', { bar: [2, 3] })).toBe('example.com?bar[]=2&bar[]=3');
29-
expect(jcurl.addParams('example.com?bar=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=2&bar[]=3&bar[]=4');
30-
expect(jcurl.addParams('example.com?bar=1&bar=2', { bar: [3, 4] })).toBe('example.com?bar[]=3&bar[]=4');
31-
expect(jcurl.addParams('example.com?bar[]=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=1&bar[]=2&bar[]=3&bar[]=4');
24+
expect(addParams('example.com', { bar: 1 })).toBe('example.com?bar=1');
25+
expect(addParams('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
26+
expect(addParams('example.com?bar=1&foo', { bar: 2 })).toBe('example.com?bar=2&foo=');
27+
expect(addParams('example.com?bar=1&foo', { bar: 2, foo: 2 })).toBe('example.com?bar=2&foo=2');
28+
expect(addParams('example.com?bar=1', { bar: [2, 3] })).toBe('example.com?bar[]=2&bar[]=3');
29+
expect(addParams('example.com?bar=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=2&bar[]=3&bar[]=4');
30+
expect(addParams('example.com?bar=1&bar=2', { bar: [3, 4] })).toBe('example.com?bar[]=3&bar[]=4');
31+
expect(addParams('example.com?bar[]=1&bar[]=2', { bar: [3, 4] })).toBe('example.com?bar[]=1&bar[]=2&bar[]=3&bar[]=4');
3232
});
3333

3434
test('addParamsExtended()', () => {
35-
expect(jcurl.addParamsExtended('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
35+
expect(addParamsExtended('example.com', { bar: 1, foo: 2 })).toBe('example.com?bar=1&foo=2');
3636
/**
3737
* BUG
3838
*/
39-
// expect(jcurl.addParamsExtended('example.com?bar[foo]=test&bar[joo]=2', { bar: { foo: 'new', too: 5 } }))
39+
// expect(addParamsExtended('example.com?bar[foo]=test&bar[joo]=2', { bar: { foo: 'new', too: 5 } }))
4040
// .toBe('example.com?bar[foo]=new&bar[joo]=2&bar[too]=5');
41-
expect(jcurl.addParamsExtended('example.com', { bar: { foo: 'test', joo: 2 } }))
41+
expect(addParamsExtended('example.com', { bar: { foo: 'test', joo: 2 } }))
4242
.toBe('example.com?bar[foo]=test&bar[joo]=2');
43-
expect(jcurl.addParamsExtended('example.com', {
43+
expect(addParamsExtended('example.com', {
4444
f1: { f11: 1, f12: 2, f13: 3 }, f2: 4, f3: { f31: { f311: 6, f312: { f3121: 9 } }, f32: { f321: 2 } },
4545
f4: { f41: 3, f42: { f421: 2 } }, f5: [2, 4]
4646
})).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');

0 commit comments

Comments
 (0)