-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update scripts and build system (#7)
- Loading branch information
Showing
10 changed files
with
282 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Regular folders | ||
dist/ | ||
node_modules/ | ||
lib | ||
|
||
# Ignore lock files | ||
*-lock.json | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
function copyRecursiveSync(src, dest) { | ||
const exists = fs.existsSync(src); | ||
const stats = exists && fs.statSync(src); | ||
const isDirectory = exists && stats.isDirectory(); | ||
|
||
if (isDirectory) { | ||
fs.mkdirSync(dest); | ||
fs.readdirSync(src).forEach(function (childItemName) { | ||
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName)); | ||
}); | ||
} else { | ||
fs.copyFileSync(src, dest); | ||
} | ||
} | ||
|
||
if (process.argv.length < 4) { | ||
process.stderr.write("Usage: node copy.js <origin1> <origin2> ... <destination>\n"); | ||
process.exit(1); | ||
} | ||
|
||
const destination = process.argv[process.argv.length - 1]; | ||
|
||
for (let i = 2; i < process.argv.length - 1; i++) { | ||
const origin = process.argv[i]; | ||
copyRecursiveSync(origin, path.join(destination, path.basename(origin))); | ||
process.stdout.write(`Copied: ${origin} to ${destination}\n`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require("fs").promises; | ||
|
||
const moveFile = async (origin, destination) => { | ||
try { | ||
await fs.access(origin); | ||
} catch (error) { | ||
process.stderr.write(`Error: Origin '${origin}' not found\n`); | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
await fs.rename(origin, destination); | ||
process.stdout.write(`Move: ${origin} to ${destination}\n`); | ||
} catch (error) { | ||
process.stderr.write(`Error: Unable to move '${origin}' to '${destination}'\n`); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
if (process.argv.length !== 4) { | ||
process.stderr.write("Usage: node mv.js <origin> <destination>\n"); | ||
process.exit(1); | ||
} | ||
|
||
const origin = process.argv[2]; | ||
const destination = process.argv[3]; | ||
|
||
moveFile(origin, destination); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require("fs").promises; | ||
|
||
const removeTarget = async (target) => { | ||
try { | ||
await fs.rm(target, { recursive: true, force: true }); | ||
process.stdout.write(`Removed: ${target}\n`); | ||
} catch (error) { | ||
process.stderr.write(`Error: Unable to remove '${target}'\n`); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
if (process.argv.length !== 3) { | ||
process.stderr.write("Usage: node rm.js <dir/file>\n"); | ||
process.exit(1); | ||
} | ||
|
||
const target = process.argv[2]; | ||
removeTarget(target); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
import { match } from '../src/match-pattern'; | ||
import { match } from "../src/match-pattern"; | ||
import { describe, test, expect } from "vitest"; | ||
|
||
describe('testing match pattern function', () => { | ||
describe("testing match pattern function", () => { | ||
const matchValidates = { | ||
0: () => "this is 0", | ||
99: () => "this is 99", | ||
"11..=22": () => "this number is in between 11 and 22", | ||
"/abc/": () => "this is a regex", | ||
"2 | 3 | 5 | 8": () => "this number is a prime number", | ||
false: () => "this is a boolean", | ||
"a..=d": () => "this is a char", | ||
"1..=13": () => "Between 1 and 13", | ||
"25 | 50 | 100": () => "A bill", | ||
"/[a-z]/": () => "A lowercase letter", | ||
_: () => "default", | ||
}; | ||
|
||
const matchValidates = { | ||
0: () => "this is 0", | ||
99: () => "this is 99", | ||
"11..=22": () => "this number is in between 11 and 22", | ||
"/abc/": () => "this is a regex", | ||
"2 | 3 | 5 | 8": () => "this number is a prime number", | ||
false: () => "this is a boolean", | ||
"a..=d": () => "this is a char", | ||
"1..=13": () => "Between 1 and 13", | ||
"25 | 50 | 100": () => "A bill", | ||
"/[a-z]/": () => "A lowercase letter", | ||
"_": () => "default", | ||
}; | ||
const enum Coin { | ||
Penny, | ||
Nickel, | ||
Dime, | ||
Quarter, | ||
} | ||
|
||
const enum Coin { | ||
Penny, | ||
Nickel, | ||
Dime, | ||
Quarter | ||
} | ||
test("match pattern - validates", () => { | ||
expect(match(0, matchValidates)).toBe("this is 0"); | ||
expect(match(99, matchValidates)).toBe("this is 99"); | ||
expect(match(11, matchValidates)).toBe("this number is in between 11 and 22"); | ||
expect(match(/abc/, matchValidates)).toBe("this is a regex"); | ||
expect(match(false, matchValidates)).toBe("this is a boolean"); | ||
expect(match("a", matchValidates)).toBe("this is a char"); | ||
expect(match(5, matchValidates)).toBe("this number is a prime number"); | ||
expect(match(10, matchValidates)).toBe("Between 1 and 13"); | ||
expect(match(25, matchValidates)).toBe("A bill"); | ||
expect(match("z", matchValidates)).toBe("A lowercase letter"); | ||
expect(match("1", matchValidates)).toBe("default"); | ||
}); | ||
|
||
test('match pattern - validates', () => { | ||
expect(match(0, matchValidates)).toBe("this is 0"); | ||
expect(match(99, matchValidates)).toBe("this is 99"); | ||
expect(match(11, matchValidates)).toBe("this number is in between 11 and 22"); | ||
expect(match(/abc/, matchValidates)).toBe("this is a regex"); | ||
expect(match(false, matchValidates)).toBe("this is a boolean"); | ||
expect(match("a", matchValidates)).toBe("this is a char"); | ||
expect(match(5, matchValidates)).toBe("this number is a prime number"); | ||
expect(match(10, matchValidates)).toBe("Between 1 and 13"); | ||
expect(match(25, matchValidates)).toBe("A bill"); | ||
expect(match("z", matchValidates)).toBe("A lowercase letter"); | ||
expect(match("1", matchValidates)).toBe("default"); | ||
}); | ||
|
||
test('match pattern - enum', () => { | ||
expect(match(Coin.Dime, { | ||
[Coin.Penny]: () => 1, | ||
[Coin.Nickel]: () => 5, | ||
[Coin.Dime]: () => 10, | ||
[Coin.Quarter]: () => 25, | ||
})).toBe(10); | ||
}); | ||
}); | ||
test("match pattern - enum", () => { | ||
expect( | ||
match(Coin.Dime, { | ||
[Coin.Penny]: () => 1, | ||
[Coin.Nickel]: () => 5, | ||
[Coin.Dime]: () => 10, | ||
[Coin.Quarter]: () => 25, | ||
}) | ||
).toBe(10); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { Some, None, Optional } from "../src/optional-pattern"; | ||
import { match } from '../src/match-pattern'; | ||
import { match } from "../src/match-pattern"; | ||
import { describe, test, expect } from "vitest"; | ||
|
||
describe("testing optional pattern function", () => { | ||
const v1: Optional<number> = Some(1); | ||
const v2: Optional<number> = None(); | ||
|
||
describe('testing optional pattern function', () => { | ||
const v1: Optional<number> = Some(1); | ||
const v2: Optional<number> = None(); | ||
test("optional pattern", () => { | ||
expect( | ||
match(v1, { | ||
Some: (x) => x + 1, | ||
None: 0, | ||
}) | ||
).toBe(2); | ||
|
||
test('optional pattern', () => { | ||
expect(match(v1, { | ||
Some: (x) => x + 1, | ||
None: 0, | ||
})).toBe(2); | ||
|
||
expect(match(v2, { | ||
Some: (x) => x + 1, | ||
None: 0, | ||
})).toBe(0); | ||
}) | ||
|
||
}) | ||
expect( | ||
match(v2, { | ||
Some: (x) => x + 1, | ||
None: 0, | ||
}) | ||
).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "ES2021", | ||
"moduleResolution": "node", | ||
"outDir": "lib/cjs", | ||
"declarationDir": "lib/cjs/types" | ||
} | ||
} |
Oops, something went wrong.