Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 26, 2024
1 parent cc232cb commit fd5a1c9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Expand Up @@ -10,9 +10,8 @@ jobs:
fail-fast: false
matrix:
node-version:
- 20
- 18
- 16
- 14
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
19 changes: 10 additions & 9 deletions base.js
Expand Up @@ -5,7 +5,7 @@ import {includeKeys} from 'filter-obj';
const isNullOrUndefined = value => value === null || value === undefined;

// eslint-disable-next-line unicorn/prefer-code-point
const strictUriEncode = string => encodeURIComponent(string).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
const strictUriEncode = string => encodeURIComponent(string).replaceAll(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);

const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');

Expand Down Expand Up @@ -87,7 +87,7 @@ function encoderForArrayFormat(options) {
case 'comma':
case 'separator':
case 'bracket-separator': {
const keyValueSep = options.arrayFormat === 'bracket-separator'
const keyValueSeparator = options.arrayFormat === 'bracket-separator'
? '[]='
: '=';

Expand All @@ -104,7 +104,7 @@ function encoderForArrayFormat(options) {
value = value === null ? '' : value;

if (result.length === 0) {
return [[encode(key, options), keyValueSep, encode(value, options)].join('')];
return [[encode(key, options), keyValueSeparator, encode(value, options)].join('')];
}

return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
Expand Down Expand Up @@ -353,7 +353,7 @@ export function parse(query, options) {
continue;
}

const parameter_ = options.decode ? parameter.replace(/\+/g, ' ') : parameter;
const parameter_ = options.decode ? parameter.replaceAll('+', ' ') : parameter;

let [key, value] = splitOnFirst(parameter_, '=');

Expand Down Expand Up @@ -395,10 +395,13 @@ export function stringify(object, options) {
return '';
}

options = {encode: true,
options = {
encode: true,
strict: true,
arrayFormat: 'none',
arrayFormatSeparator: ',', ...options};
arrayFormatSeparator: ',',
...options,
};

validateArrayFormatSeparator(options.arrayFormatSeparator);

Expand Down Expand Up @@ -484,9 +487,7 @@ export function stringifyUrl(object, options) {
};

let queryString = stringify(query, options);
if (queryString) {
queryString = `?${queryString}`;
}
queryString &&= `?${queryString}`;

let hash = getHash(object.url);
if (typeof object.fragmentIdentifier === 'string') {
Expand Down
4 changes: 2 additions & 2 deletions benchmark.js
Expand Up @@ -24,10 +24,10 @@ const TEST_URL = stringifyUrl({url: TEST_HOST, query: TEST_OBJECT});

// Creates a test case and adds it to the suite
const defineTestCase = (methodName, input, options) => {
const fn = queryString[methodName];
const function_ = queryString[methodName];
const label = options ? ` (${stringify(options)})` : '';

suite.add(methodName + label, () => fn(input, options || {}));
suite.add(methodName + label, () => function_(input, options || {}));
};

// Define all test cases
Expand Down
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -17,7 +17,7 @@
},
"sideEffects": false,
"engines": {
"node": ">=14.16"
"node": ">=18"
},
"scripts": {
"benchmark": "node benchmark.js",
Expand Down Expand Up @@ -51,12 +51,12 @@
"split-on-first": "^3.0.0"
},
"devDependencies": {
"ava": "^5.1.0",
"ava": "^6.1.1",
"benchmark": "^2.1.4",
"deep-equal": "^2.1.0",
"fast-check": "^3.4.0",
"tsd": "^0.25.0",
"xo": "^0.54.2"
"deep-equal": "^2.2.3",
"fast-check": "^3.15.1",
"tsd": "^0.30.7",
"xo": "^0.57.0"
},
"tsd": {
"compilerOptions": {
Expand Down
1 change: 0 additions & 1 deletion test/parse-url.js
Expand Up @@ -2,7 +2,6 @@ import test from 'ava';
import queryString from '../index.js';

test('handles strings with query string', t => {
console.log('f', queryString.parseUrl('https://foo.bar#top?foo=bar'));
t.deepEqual(queryString.parseUrl('https://foo.bar#top?foo=bar'), {url: 'https://foo.bar', query: {}});
t.deepEqual(queryString.parseUrl('https://foo.bar?foo=bar&foo=baz#top'), {url: 'https://foo.bar', query: {foo: ['bar', 'baz']}});
t.deepEqual(queryString.parseUrl('https://foo.bar?foo=bar&foo=baz'), {url: 'https://foo.bar', query: {foo: ['bar', 'baz']}});
Expand Down

0 comments on commit fd5a1c9

Please sign in to comment.