Skip to content

Commit

Permalink
feat: adjust release script
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz committed Aug 1, 2024
1 parent ac38096 commit 8601abf
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 81 deletions.
108 changes: 54 additions & 54 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@expressots/core": "2.15.0",
"@release-it/conventional-changelog": "8.0.1",
"@types/express": "4.17.21",
"@types/node": "20.14.10",
"@types/node": "22.0.2",
"@typescript-eslint/eslint-plugin": "7.16.1",
"@typescript-eslint/parser": "7.16.1",
"@vitest/coverage-v8": "2.0.3",
Expand All @@ -82,60 +82,60 @@
"rimraf": "6.0.1"
},
"release-it": {
"git": {
"commitMessage": "chore(release): ${version}"
},
"github": {
"release": true
},
"npm": {
"publish": false
},
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "refactor",
"section": "Code Refactoring"
},
{
"type": "test",
"section": "Tests"
},
{
"type": "build",
"section": "Build System"
},
{
"type": "ci",
"section": "Continuous Integrations"
"git": {
"commitMessage": "chore(release): ${version}"
},
"github": {
"release": true
},
"npm": {
"publish": false
},
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "refactor",
"section": "Code Refactoring"
},
{
"type": "test",
"section": "Tests"
},
{
"type": "build",
"section": "Build System"
},
{
"type": "ci",
"section": "Continuous Integrations"
}
]
}
}
]
}
}
}
}
}
55 changes: 28 additions & 27 deletions src/match-pattern.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
/* type None = { tag: "None" };
type Some<T> = { tag: "Some", value: T};
export type Optional<T> = Some<T> | None;
export function Some<T>(value: T): Some<T> {
return { tag: "Some", value };
}
export function None(): None {
return { tag: "None" };
} */

import { None, Some } from "./optional-pattern";

function isSome(value: any): value is Some<any> {
Expand All @@ -23,39 +11,53 @@ function isNone(value: any): value is None {
type OptionalPattern<T, U> = {
Some?: (value: U) => T;
None?: T;
}
};

type MatchPatterns<T, U> = {
[key: string]: () => T;
} | OptionalPattern<T, U>;
type MatchPatterns<T, U> =
| {
[key: string]: () => T;
}
| OptionalPattern<T, U>;

export function match<T, U = never>(value: any, patterns: MatchPatterns<T, U>): T {

if (isSome(value) && patterns.Some) {
return patterns.Some(value.value);
} else if (isNone(value) && patterns.None !== undefined) {
return patterns.None as T;
}

for (const p in patterns) {

for (const p in patterns) {
if (p === "Some" || p === "None") continue;

const patternKey = String(p);
const isRange = patternKey.includes("..=");
const isOr = patternKey.includes("|");
const isRegex = patternKey.startsWith("/") && patternKey.endsWith("/");

if (isRange) {
const [start, end] = patternKey.split("..=").map(s => isNaN(Number(s)) ? s : Number(s));

if ((typeof value === "number" && typeof start === "number" && typeof end === "number" && value >= start && value <= end) ||
(typeof value === "string" && typeof start === "string" && typeof end === "string" && value >= start && value <= end)) {
if (isRange) {
const [start, end] = patternKey
.split("..=")
.map((s) => (isNaN(Number(s)) ? s : Number(s)));

if (
(typeof value === "number" &&
typeof start === "number" &&
typeof end === "number" &&
value >= start &&
value <= end) ||
(typeof value === "string" &&
typeof start === "string" &&
typeof end === "string" &&
value >= start &&
value <= end)
) {
return patterns[p]();
}
} else if (isOr) {
const patternValues = patternKey.split("|").map(s => isNaN(Number(s)) ? s : Number(s));

const patternValues = patternKey
.split("|")
.map((s) => (isNaN(Number(s)) ? s : Number(s)));

if (patternValues.includes(value)) {
return patterns[p]();
}
Expand All @@ -65,7 +67,6 @@ export function match<T, U = never>(value: any, patterns: MatchPatterns<T, U>):
if (regex.test(value)) {
return patterns[p]();
}

} else {
if (value.toString() === patternKey) {
return patterns[p]();
Expand Down

0 comments on commit 8601abf

Please sign in to comment.