Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace rome with biome #28

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules
build/
coverage
.vscode
20 changes: 20 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": true
},
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"indentStyle": "space"
}
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
],
"scripts": {
"build": "tsc",
"format": "rome format src",
"lint": "rome check src",
"test": "rome ci src && vitest --run --coverage",
"lint": "biome check .",
"test": "biome ci . && vitest --run --coverage",
"prepublish": "npm run build"
},
"keywords": [
Expand All @@ -27,10 +26,10 @@
"author": "Erik Müller",
"license": "MIT",
"devDependencies": {
"@biomejs/biome": "1.4.1",
"@vitest/coverage-c8": "^0.25.3",
"typescript": "^4.9.3",
"vitest": "^0.25.3",
"rome": "^10.0.1"
"vitest": "^0.25.3"
},
"type": "module"
"type": "module"
}
8 changes: 0 additions & 8 deletions rome.json

This file was deleted.

46 changes: 23 additions & 23 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ import { expect, it } from "vitest";
import cond from "./index.js";

it("returns the first value for which the predicate evaluates to true", () => {
const value = cond([
[false, "false"],
[true, "true"],
[true, "true but too late"],
]);
const value = cond([
[false, "false"],
[true, "true"],
[true, "true but too late"],
]);

expect(value).toBe("true");
expect(value).toBe("true");
});

it("returns undefined if no predicate evaluates to true", () => {
const value = cond([[false, "false"]]);
const value = cond([[false, "false"]]);

expect(value).toBeUndefined();
expect(value).toBeUndefined();
});

it("returns provided fallback if no predicate evaluates to true", () => {
const value = cond([[false, "false"]], {
default: () => "fallback",
});
const value = cond([[false, "false"]], {
default: () => "fallback",
});

expect(value).toBe("fallback");
expect(value).toBe("fallback");
});

it("Accepts functions as value for lazy evaluation", () => {
const value = cond<string>([
[
false,
() => {
throw new Error("duh!");
},
],
[true, () => "true"],
]);

expect(value).toBe("true");
const value = cond<string>([
[
false,
() => {
throw new Error("duh!");
},
],
[true, () => "true"],
]);

expect(value).toBe("true");
});
32 changes: 16 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ type Value<T> = T | (() => T);
type Pairs<T> = [boolean, Value<T>][];

type Options<T> = {
/**
* If no match is found, the default is returned instead.
* @default undefined
*/
default?: Value<T>;
/**
* If no match is found, the default is returned instead.
* @default undefined
*/
default?: Value<T>;
};

// Ignoring rule to allow for usage of interface
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface Cond {
<T, F extends undefined>(pairs: Pairs<T>, options?: F): T | undefined;
<T, F extends Value<T>>(
pairs: Pairs<T>,
options?: { default: F },
): F extends Value<T> ? T : T | undefined;
<T>(pairs: Pairs<T>, options?: Options<T>): T | undefined;
<T, F extends undefined>(pairs: Pairs<T>, options?: F): T | undefined;
<T1, F1 extends Value<T1>>(
pairs: Pairs<T1>,
options?: { default: F1 },
): F1 extends Value<T1> ? T1 : T1 | undefined;
<T2>(pairs: Pairs<T2>, options?: Options<T2>): T2 | undefined;
}

// Manual type guard is necessary, see https://stackoverflow.com/questions/62500700/error-2349-when-dealing-with-union-type-of-generic-t-and-function
function isFunction<T>(value: T | (() => T)): value is () => T {
return typeof value === "function";
return typeof value === "function";
}

function processMatch<T>(match: Value<T>): T {
return isFunction<T>(match) ? match() : match;
return isFunction<T>(match) ? match() : match;
}

const cond: Cond = <T, F>(pairs: Pairs<T>, options?: Options<F>) => {
const found = pairs.find(([predicate]) => predicate);
const match = found === undefined ? options?.default : found[1];
const found = pairs.find(([predicate]) => predicate);
const match = found === undefined ? options?.default : found[1];

return processMatch(match);
return processMatch(match);
};

export default cond;
12 changes: 6 additions & 6 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, "build"],
coverage: {
reporter: ["text", "html", "cobertura"],
},
},
test: {
exclude: [...configDefaults.exclude, "build"],
coverage: {
reporter: ["text", "html", "cobertura"],
},
},
});
84 changes: 42 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,48 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-1.4.1.tgz#b698c67ea8cd8141c8e27f857c8e6e794320a251"
integrity sha512-JccVAwPbhi37pdxbAGmaOBjUTKEwEjWAhl7rKkVVuXHo4MLASXJ5HR8BTgrImi4/7rTBsGz1tgVD1Kwv1CHGRg==
optionalDependencies:
"@biomejs/cli-darwin-arm64" "1.4.1"
"@biomejs/cli-darwin-x64" "1.4.1"
"@biomejs/cli-linux-arm64" "1.4.1"
"@biomejs/cli-linux-x64" "1.4.1"
"@biomejs/cli-win32-arm64" "1.4.1"
"@biomejs/cli-win32-x64" "1.4.1"

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.4.1.tgz#75f9c3c9b1abed8836c8f7bc8cd23ba153fb93d1"
integrity sha512-PZWy2Idndqux38p6AXSDQM2ldRAWi32bvb7bMbTN0ALzpWYMYnxd71ornatumSSJYoNhKmxzDLq+jct7nZJ79w==

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.4.1.tgz#672fcce2d339de3bb7a7bd2997e94f03121a28a3"
integrity sha512-soj3BWhnsM1M2JlzR09cibUzG1owJqetwj/Oo7yg0foijo9lNH9XWXZfJBYDKgW/6Fomn+CC2EcUS+hisQzt9g==

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.4.1.tgz#c816206089ad29ce866c58a6e00e9d3d64a3529d"
integrity sha512-YIZqfJUg4F+fPsBTXxgD7EU2E5OAYbmYSl/snf4PevwfQCWE/omOFZv+NnIQmjYj9I7ParDgcJvanoA3/kO0JQ==

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64/-/cli-linux-x64-1.4.1.tgz#2639daeab1be205cfe444a8d5a3f76aa3a59b956"
integrity sha512-9YOZw3qBd/KUj63A6Hn2zZgzGb2nbESM0qNmeMXgmqinVKM//uc4OgY5TuKITuGjMSvcVxxd4dX1IzYjV9qvNQ==

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.4.1.tgz#ed5e749b2e0987cf16b545beaa01be6980ae8ce1"
integrity sha512-nWQbvkNKxYn/kCQ0yVF8kCaS3VzaGvtFSmItXiMknU4521LDjJ7tNWH12Gol+pIslrCbd4E1LhJa0a3ThRsBVg==

"@biomejs/[email protected]":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-x64/-/cli-win32-x64-1.4.1.tgz#dd8ee6e14a5d74cbeb2eb9824a43c61bb5c460e4"
integrity sha512-88fR2CQxQ4YLs2BUDuywWYQpUKgU3A3sTezANFc/4LGKQFFLV2yX+F7QAdZVkMHfA+RD9Xg178HomM/6mnTNPA==

"@esbuild/[email protected]":
version "0.15.16"
resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.15.16.tgz#0642926178b15e3d1545efae6eee05c4f3451d15"
Expand Down Expand Up @@ -40,36 +82,6 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@rometools/[email protected]":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@rometools/cli-darwin-arm64/-/cli-darwin-arm64-10.0.1.tgz#de60ad5879d9b02ca24b707c17f2f8c372624b3c"
integrity sha512-MwQjk3uhZrCu6LgIwJHREAsVt/mUQTGv7p8iosfaF8lCIxMVjyS+akbF/QcBufyW5sFtHYNWUEe/uKPHK4E//A==

"@rometools/[email protected]":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@rometools/cli-darwin-x64/-/cli-darwin-x64-10.0.1.tgz#f4f39e02af164841700cb452b52a111361cef345"
integrity sha512-n010Wc/z9L8wRkRnR5boMhdWgDVGrTG/i7zL8u/3+F5aSUgLCywf9F/b3ex74tCJJfcwBLlhaAqAVQX6U1bIkA==

"@rometools/[email protected]":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@rometools/cli-linux-arm64/-/cli-linux-arm64-10.0.1.tgz#3b3977429873b17459b02db9ee95681bb016a3d6"
integrity sha512-JljZsnud1KCfe36VNsVh/LrYdAzgbKbcsCTzeCjW9ROkMyNj8pmQ/gIUFxZ+PyhMFgowHIDGihoNf4m+pgpxkA==

"@rometools/[email protected]":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@rometools/cli-linux-x64/-/cli-linux-x64-10.0.1.tgz#2f01698504c1d634623a7bde6faad09ad2deb1b0"
integrity sha512-jXIqd9iDyZUexk63CRfAXDA4zNDUHpErUmCejjGab3dhDt1KA40fDqKb+kxZpAhY3tQoWNSNQyo750zX5NawLw==

"@rometools/[email protected]":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@rometools/cli-win32-arm64/-/cli-win32-arm64-10.0.1.tgz#2b573f34a33ce477bc4f03bf93358954ea531f05"
integrity sha512-G/toRrKPhhi7SMYMyROq/E2c8/4xRX/67vFhVihuMvDDzhanIb99hEt5MMbM4HbYK1nnZBPyLN6LxVsxm9M9hA==

"@rometools/[email protected]":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@rometools/cli-win32-x64/-/cli-win32-x64-10.0.1.tgz#f643480fd72e8dfdbc5a3e3ccb27646cd2fb2dc0"
integrity sha512-y299+VGoBufZntZj0Xz7w9DODU+6E5giXStfBDoa0fspXGNkYyYfD+HC6j9gUv4zpMZJ607XVvVHjpfwM/3ftA==

"@types/chai-subset@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@types/chai-subset/-/chai-subset-1.3.3.tgz#97893814e92abd2c534de422cb377e0e0bdaac94"
Expand Down Expand Up @@ -639,18 +651,6 @@ rollup@^2.79.1:
optionalDependencies:
fsevents "~2.3.2"

rome@^10.0.1:
version "10.0.1"
resolved "https://registry.yarnpkg.com/rome/-/rome-10.0.1.tgz#3974603123b75ecbf98b306bcda8b7fa007c80b0"
integrity sha512-RfaDa+cSustBsjX6bj3fWqEhoNxXrK1uNgKHpkCHAqp20QMJXnCRtbokhirNMe0utyGI9GTO/sDoK7hJP7O8Bw==
optionalDependencies:
"@rometools/cli-darwin-arm64" "10.0.1"
"@rometools/cli-darwin-x64" "10.0.1"
"@rometools/cli-linux-arm64" "10.0.1"
"@rometools/cli-linux-x64" "10.0.1"
"@rometools/cli-win32-arm64" "10.0.1"
"@rometools/cli-win32-x64" "10.0.1"

semver@^6.0.0:
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
Expand Down
Loading