Skip to content

Commit

Permalink
feat: replace rome with biome
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jul 9, 2024
1 parent 44221cf commit f148dec
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 53 deletions.
6 changes: 2 additions & 4 deletions benchmark/bench-cmp-branch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

const { spawn } = require("node:child_process");

const cliSelect = require("cli-select");
Expand Down Expand Up @@ -56,7 +54,7 @@ function parseBenchmarksStdout(text) {
results.push({
name: match[1],
alignedName: match[1] + match[2],
result: parseInt(match[3].split(",").join("")),
result: Number.parseInt(match[3].split(",").join("")),
});
}
}
Expand Down Expand Up @@ -90,7 +88,7 @@ function compareResults(featureBranch, mainBranch) {
}
}

(async function () {
(async () => {
const branches = await git.branch();
const currentBranch = branches.branches[branches.current];

Expand Down
2 changes: 0 additions & 2 deletions benchmark/bench-thread.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

const { workerData: benchmark, parentPort } = require("node:worker_threads");

const Benchmark = require("benchmark");
Expand Down
4 changes: 1 addition & 3 deletions benchmark/bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

const path = require("node:path");
const { Worker } = require("node:worker_threads");

Expand Down Expand Up @@ -69,7 +67,7 @@ const benchmarks = [
{
type: "stringify",
name: "{ id: Infinity }",
input: { id: Infinity },
input: { id: Number.POSITIVE_INFINITY },
},
{
type: "stringify",
Expand Down
6 changes: 3 additions & 3 deletions benchmark/parse.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import native from "node:querystring";
import awsQueryStringParser from "@aws-sdk/querystring-parser";
import benchmark from "cronometro";
import qs from "qs";
import fastQueryString from "../lib/index.js";
import native from "node:querystring";
import queryString from "query-string";
import querystringify from "querystringify";
import awsQueryStringParser from "@aws-sdk/querystring-parser";
import querystringparser from "querystringparser";
import fastQueryString from "../lib/index.js";

const input = "frappucino=muffin&goat=scone&pond=moose&foo=bar&foo=baz";

Expand Down
10 changes: 5 additions & 5 deletions benchmark/stringify.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import native from "node:querystring";
import awsQueryStringBuilder from "@aws-sdk/querystring-builder";
import benchmark from "cronometro";
import httpQuerystringStringify from "http-querystring-stringify";
import qs from "qs";
import fastQueryString from "../lib/index.js";
import native from "node:querystring";
import queryString from "query-string";
import querystringify from "querystringify";
import httpQuerystringStringify from "http-querystring-stringify";
import awsQueryStringBuilder from "@aws-sdk/querystring-builder";
import querystringparser from "querystringparser";
import querystringifyQs from "querystringify-ts";
import querystringparser from "querystringparser";
import fastQueryString from "../lib/index.js";

const value = {
frappucino: "muffin",
Expand Down
25 changes: 25 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"linter": {
"enabled": true,
"rules": {
"complexity": {
"all": false
},
"style": {
"all": false
},
"suspicious": {
"noRedundantUseStrict": "off"
}
}
},
"organizeImports": {
"enabled": true
}
}
4 changes: 4 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
type FastQueryString = {
// biome-ignore lint/suspicious/noExplicitAny: This is deliberate.
stringify(value: Record<string, any>): string;
// biome-ignore lint/suspicious/noExplicitAny: This is deliberate.
parse(value: string): Record<string, any>;
};

declare namespace fastQueryString {
// biome-ignore lint/suspicious/noExplicitAny: This is deliberate.
export function stringify(value: Record<string, any>): string;
// biome-ignore lint/suspicious/noExplicitAny: This is deliberate.
export function parse(value: string): Record<string, any>;

const fqs: FastQueryString;
Expand Down
2 changes: 1 addition & 1 deletion lib/internals/querystring.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const hexTable = Array.from(
// digits
// alpha (uppercase)
// alpha (lowercase)
// rome-ignore format: the array should not be formatted
// biome-ignore format: the array should not be formatted
const noEscape = new Int8Array([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function parse(input) {
return result;
}

let inputLength = input.length;
const inputLength = input.length;
let key = "";
let value = "";
let startingIndex = -1;
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"type": "commonjs",
"types": "./lib/index.d.ts",
"scripts": {
"format": "rome format . --write",
"format:ci": "rome ci .",
"format": "biome check . --write",
"format:ci": "rome check .",
"test": "vitest",
"test:environment:edge": "vitest --environment=edge-runtime",
"test:environment:browser": "vitest --environment=jsdom",
Expand All @@ -20,16 +20,13 @@
"benchmark:stringify": "node benchmark/stringify.mjs",
"benchmark:import": "node benchmark/import.mjs"
},
"keywords": [
"querystring",
"qs",
"parser"
],
"keywords": ["querystring", "qs", "parser"],
"author": "Yagiz Nizipli <[email protected]>",
"license": "MIT",
"devDependencies": {
"@aws-sdk/querystring-builder": "^3.357.0",
"@aws-sdk/querystring-parser": "^3.357.0",
"@biomejs/biome": "1.8.3",
"@edge-runtime/vm": "^3.0.3",
"@types/node": "^20.4.1",
"@vitest/coverage-v8": "^0.34.1",
Expand All @@ -43,7 +40,6 @@
"querystringify": "^2.2.0",
"querystringify-ts": "^0.1.5",
"querystringparser": "^0.1.1",
"rome": "12.1.3",
"simple-git": "^3.19.1",
"vitest": "^0.34.1"
},
Expand Down
9 changes: 0 additions & 9 deletions rome.json

This file was deleted.

6 changes: 3 additions & 3 deletions test/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const qsTestCases = [
];
export const qsWeirdObjects = [
[{ regexp: /./g }, "regexp=", { regexp: "" }],
[{ regexp: new RegExp(".", "g") }, "regexp=", { regexp: "" }],
[{ regexp: /./g }, "regexp=", { regexp: "" }],
[{ fn: () => {} }, "fn=", { fn: "" }],
[{ fn: new Function("") }, "fn=", { fn: "" }],
[{ math: Math }, "math=", { math: "" }],
Expand All @@ -127,8 +127,8 @@ export const qsWeirdObjects = [
[{ f: new Boolean(false), t: new Boolean(true) }, "f=&t=", { f: "", t: "" }],
[{ f: false, t: true }, "f=false&t=true", { f: "false", t: "true" }],
[{ n: null }, "n=", { n: "" }],
[{ nan: NaN }, "nan=", { nan: "" }],
[{ inf: Infinity }, "inf=", { inf: "" }],
[{ nan: Number.NaN }, "nan=", { nan: "" }],
[{ inf: Number.POSITIVE_INFINITY }, "inf=", { inf: "" }],
[{ a: [], b: [] }, "", {}],
[{ a: 1, b: [] }, "a=1", { a: "1" }],
];
6 changes: 3 additions & 3 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import querystring from "querystring";
import { assert, test } from "vitest";
import qs from "../lib";
import { test, assert } from "vitest";
import { qsNoMungeTestCases, qsTestCases, qsWeirdObjects } from "./node";
import querystring from "querystring";

test("should succeed on node.js tests", () => {
qsWeirdObjects.forEach((t) =>
assert.deepEqual(qs.parse(t[1] as string), t[2] as Record<string, any>),
assert.deepEqual(qs.parse(t[1] as string), t[2] as Record<string, unknown>),
);
qsNoMungeTestCases.forEach((t) => assert.deepEqual(qs.parse(t[0]), t[1]));
qsTestCases.forEach((t) => assert.deepEqual(qs.parse(t[0]), t[2]));
Expand Down
25 changes: 14 additions & 11 deletions test/stringify.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { qsNoMungeTestCases, qsTestCases, qsWeirdObjects } from "./node";
import qs from "../lib";
import { test, assert } from "vitest";
import querystring from "querystring";
import { assert, test } from "vitest";
import qs from "../lib";
import { qsNoMungeTestCases, qsTestCases, qsWeirdObjects } from "./node";

test("should succeed on node.js tests", () => {
qsWeirdObjects.forEach((t) =>
assert.deepEqual(qs.stringify(t[2] as Record<string, any>), t[1] as string),
assert.deepEqual(
qs.stringify(t[2] as Record<string, unknown>),
t[1] as string,
),
);
qsNoMungeTestCases.forEach((t) => assert.deepEqual(qs.stringify(t[1]), t[0]));
qsTestCases.forEach((t) => assert.deepEqual(qs.stringify(t[2]), t[1]));
Expand Down Expand Up @@ -55,7 +58,7 @@ test("should omit objects", () => {
});

test("should omit non-object inputs", () => {
assert.deepEqual(qs.stringify("hello" as any), "");
assert.deepEqual(qs.stringify("hello" as never), "");
});

test("should handle utf16 characters", () => {
Expand Down Expand Up @@ -89,15 +92,15 @@ test("should coerce numbers to string", () => {
assert.strictEqual(qs.stringify({ foo: -0 }), "foo=0");
assert.strictEqual(qs.stringify({ foo: 3 }), "foo=3");
assert.strictEqual(qs.stringify({ foo: -72.42 }), "foo=-72.42");
assert.strictEqual(qs.stringify({ foo: NaN }), "foo=");
assert.strictEqual(qs.stringify({ foo: Number.NaN }), "foo=");
assert.strictEqual(qs.stringify({ foo: 1e21 }), "foo=1e%2B21");
assert.strictEqual(qs.stringify({ foo: Infinity }), "foo=");
assert.strictEqual(qs.stringify({ foo: Number.POSITIVE_INFINITY }), "foo=");
});

test("should return empty string on certain inputs", () => {
assert.strictEqual(qs.stringify(), "");
assert.strictEqual(qs.stringify(0), "");
assert.strictEqual(qs.stringify(undefined as never), "");
assert.strictEqual(qs.stringify(0 as never), "");
assert.strictEqual(qs.stringify([]), "");
assert.strictEqual(qs.stringify(null), "");
assert.strictEqual(qs.stringify(true), "");
assert.strictEqual(qs.stringify(null as never), "");
assert.strictEqual(qs.stringify(true as never), "");
});

0 comments on commit f148dec

Please sign in to comment.