-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add type guards for various data types and implement behavioral tests #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
14432b8
feat: add type guards for various data types and implement behavioral…
Coderrob d1cd339
chore: refactoring ftw with tighter code
Coderrob a6a5170
refactor: reorganize benchmark and test descriptions for clarity
Coderrob 12c2b95
chore: update release workflow to trigger on manual dispatch only
Coderrob 5bbd712
feat: add dependabot configuration for npm and GitHub Actions updates
Coderrob 5f733bc
feat: add consumer fixtures and smoke tests for type guards
Coderrob 4d95fdd
refactor: update smoke tests to use ESM and improve package handling
Coderrob e2619b3
chore: update Node.js version requirement to 20 in package files and …
Coderrob d58b26a
refactor: update Node.js version requirements and improve test imports
Coderrob 74a4629
feat: add benchmarks section to README and update package dependencies
Coderrob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| # Changesets | ||
|
|
||
| This repository uses Changesets for versioning and changelog automation. | ||
|
|
||
| ## Common commands | ||
|
|
||
| ```bash | ||
| npm run changeset | ||
| npm run changeset:version | ||
| npm run changeset:publish | ||
| ``` | ||
|
|
||
| Create a changeset whenever a pull request changes the published package in a way | ||
| that should produce a new version or changelog entry. |
This file contains hidden or 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,11 @@ | ||
| { | ||
| "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json", | ||
| "changelog": "@changesets/cli/changelog", | ||
| "commit": false, | ||
| "fixed": [], | ||
| "linked": [], | ||
| "access": "public", | ||
| "baseBranch": "main", | ||
| "updateInternalDependencies": "patch", | ||
| "ignore": [] | ||
| } |
This file contains hidden or 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,24 @@ | ||
| version: 2 | ||
|
|
||
| updates: | ||
| - package-ecosystem: npm | ||
| directory: / | ||
| schedule: | ||
| interval: weekly | ||
| day: monday | ||
| open-pull-requests-limit: 5 | ||
| commit-message: | ||
| prefix: chore | ||
| groups: | ||
| npm-dependencies: | ||
| patterns: | ||
| - '*' | ||
|
|
||
| - package-ecosystem: github-actions | ||
| directory: / | ||
| schedule: | ||
| interval: weekly | ||
| day: monday | ||
| open-pull-requests-limit: 3 | ||
| commit-message: | ||
| prefix: chore |
This file contains hidden or 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 hidden or 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,41 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| cache: npm | ||
| registry-url: https://registry.npmjs.org | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Create release PR or publish package | ||
| uses: changesets/action@v1 | ||
| with: | ||
| version: npm run changeset:version | ||
| publish: npm run release:publish | ||
| commit: 'chore: version package' | ||
| title: 'chore: version package' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| NPM_CONFIG_PROVENANCE: true |
This file contains hidden or 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 @@ | ||
| node_modules/ | ||
| dist/ | ||
| coverage/ | ||
| .tmp/ | ||
| .npm-cache/ | ||
| *.js.map | ||
| *.tsbuildinfo |
This file contains hidden or 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 hidden or 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,55 @@ | ||
| import { Bench } from 'tinybench'; | ||
|
|
||
| import { | ||
| createEnumGuard, | ||
| isNumber, | ||
| isPlainObject, | ||
| isString, | ||
| } from '../dist/index.mjs'; | ||
|
|
||
| const ITERATION_COUNT = Number('10000'); | ||
| const BENCH_DURATION_MS = Number('100'); | ||
| const NUMERIC_VALUE = Number('42'); | ||
|
|
||
| const isStatus = createEnumGuard( | ||
| { | ||
| Active: 'ACTIVE', | ||
| Inactive: 'INACTIVE', | ||
| }, | ||
| 'Status', | ||
| ); | ||
|
|
||
| const bench = new Bench({ | ||
| iterations: ITERATION_COUNT, | ||
| time: BENCH_DURATION_MS, | ||
| }); | ||
|
|
||
| /** Benchmarks an enum guard against a positive enum value input. */ | ||
| function benchmarkEnumGuard() { | ||
| isStatus('ACTIVE'); | ||
| } | ||
|
|
||
| /** Benchmarks `isNumber` against a positive number input. */ | ||
| function benchmarkNumberGuard() { | ||
| isNumber(NUMERIC_VALUE); | ||
| } | ||
|
|
||
| /** Benchmarks `isPlainObject` against a plain object input. */ | ||
| function benchmarkPlainObjectGuard() { | ||
| isPlainObject({ answer: NUMERIC_VALUE }); | ||
| } | ||
|
|
||
| /** Benchmarks `isString` against a positive string input. */ | ||
| function benchmarkStringGuard() { | ||
| isString('guard'); | ||
| } | ||
|
|
||
| bench | ||
| .add('isString on string', benchmarkStringGuard) | ||
| .add('isNumber on number', benchmarkNumberGuard) | ||
| .add('isPlainObject on object', benchmarkPlainObjectGuard) | ||
| .add('createEnumGuard result on enum value', benchmarkEnumGuard); | ||
|
|
||
| await bench.run(); | ||
|
|
||
| console.table(bench.table()); |
This file contains hidden or 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 hidden or 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,7 @@ | ||
| { | ||
| "name": "cjs-consumer-fixture", | ||
| "private": true, | ||
| "scripts": { | ||
| "smoke": "node smoke.mjs" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.