-
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.
- Loading branch information
1 parent
f9a2667
commit ba4b49f
Showing
9 changed files
with
212 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'type-guarden': patch | ||
--- | ||
|
||
Initial release |
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 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@aacc/babel-preset", | ||
{ | ||
"typescript": true | ||
} | ||
] | ||
] | ||
} |
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,12 @@ | ||
/** | ||
* @type {import('eslint').Linter.Config} | ||
*/ | ||
module.exports = { | ||
root: true, | ||
extends: ['@aacc/eslint-config/typescript'], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: 'tsconfig.eslint.json', | ||
}, | ||
ignorePatterns: ['node_modules', 'dist'], | ||
} |
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 @@ | ||
# type-guarden | ||
|
||
Collection of type guards for TypeScript. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install type-guarden | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { isKeyOf, isValueOf } from 'type-guarden' | ||
|
||
const obj = { | ||
foo: 'bar', | ||
baz: 42, | ||
} | ||
|
||
const arr = ['foo', 'bar', 'baz'] | ||
|
||
if (isKeyOf(obj, key)) { | ||
// `key` is 'foo' | 'baz' | ||
} | ||
|
||
if (isValueOf(arr, value)) { | ||
// `value` is 'foo' | 'bar' | 'baz' | ||
} | ||
``` |
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,62 @@ | ||
{ | ||
"name": "type-guarden", | ||
"version": "0.0.0", | ||
"description": "Collection of type guards for TypeScript", | ||
"author": "Aaron Casanova <aaronccasanova@gmail.com>", | ||
"license": "MIT", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.mjs", | ||
"browser": "dist/browser/index.js", | ||
"types": "dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"dev": "npm-run-all --parallel 'build:* -- --watch'", | ||
"build": "npm-run-all --parallel build:*", | ||
"build:js": "rollup -c", | ||
"build:types": "tsc --emitDeclarationOnly", | ||
"type-check": "tsc --noEmit", | ||
"type-check:watch": "npm run type-check -- --watch", | ||
"lint": "TIMING=1 eslint . --ext .js,.ts --cache", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"peerDependencies": {}, | ||
"dependencies": { | ||
"the-answer": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@aacc/babel-preset": "*", | ||
"@aacc/browserslist-config": "*", | ||
"@aacc/eslint-config": "*", | ||
"@aacc/tsconfigs": "*", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-commonjs": "^21.1.0", | ||
"@rollup/plugin-node-resolve": "^13.2.1", | ||
"rollup": "^2.70.2", | ||
"typescript": "^4.7.3" | ||
}, | ||
"browserslist": [ | ||
"extends @aacc/browserslist-config" | ||
], | ||
"publishConfig": { | ||
"access": "public", | ||
"@aacc:registry": "https://registry.npmjs.org" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/aaronccasanova/aacc.git", | ||
"directory": "packages/type-guarden" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/aaronccasanova/aacc/issues" | ||
}, | ||
"homepage": "https://github.com/aaronccasanova/aacc/blob/main/packages/type-guarden/README.md" | ||
} |
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,57 @@ | ||
import path from 'path' | ||
|
||
import nodeResolve from '@rollup/plugin-node-resolve' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import babel from '@rollup/plugin-babel' | ||
|
||
import pkg from './package.json' | ||
|
||
const name = 'typeGuarden' | ||
|
||
const extensions = ['.js', '.jsx', '.ts', '.tsx'] | ||
|
||
/** | ||
* @type {import('rollup').RollupOptions} | ||
*/ | ||
export default { | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
format: /** @type {const} */ ('cjs'), | ||
entryFileNames: '[name][assetExtname].js', | ||
dir: path.dirname(pkg.main), | ||
preserveModules: true, | ||
}, | ||
{ | ||
format: /** @type {const} */ ('es'), | ||
entryFileNames: '[name][assetExtname].mjs', | ||
dir: path.dirname(pkg.module), | ||
preserveModules: true, | ||
}, | ||
{ | ||
format: /** @type {const} */ ('iife'), | ||
file: pkg.browser, | ||
name, | ||
|
||
// https://rollupjs.org/guide/en/#outputglobals | ||
// globals: {}, | ||
}, | ||
], | ||
plugins: [ | ||
// Allows node_modules resolution | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
nodeResolve({ extensions }), | ||
// Allow bundling cjs modules. Rollup doesn't understand cjs | ||
commonjs(), | ||
// Compile TypeScript/JavaScript files | ||
babel({ | ||
extensions, | ||
babelHelpers: 'bundled', | ||
include: ['src/**/*'], | ||
}), | ||
], | ||
external: [ | ||
...Object.keys(pkg.dependencies ?? {}), | ||
...Object.keys(pkg.peerDependencies ?? {}), | ||
], | ||
} |
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,13 @@ | ||
export function isKeyOf<T extends { [key: string]: any }>( | ||
obj: T, | ||
key?: PropertyKey | undefined, | ||
): key is keyof T { | ||
return Object.keys(obj).includes(key as string) | ||
} | ||
|
||
export function isValueOf<T extends readonly any[]>( | ||
arr: T, | ||
value?: any | undefined, | ||
): value is T[number] { | ||
return arr.includes(value) | ||
} |
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,14 @@ | ||
{ | ||
// https://typescript-eslint.io/docs/linting/monorepo#one-root-tsconfigjson | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
// Ensures this config is not used for a build | ||
"noEmit": true | ||
}, | ||
"include": [ | ||
// Paths to lint | ||
"src", | ||
".eslintrc.js", | ||
"rollup.config.js" | ||
] | ||
} |
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,9 @@ | ||
{ | ||
"extends": "@aacc/tsconfigs/node-library.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"declarationDir": "dist/types" | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
ba4b49f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
aacc-scales – ./apps/scales
aacc-scales-git-main-aaronccasanova-gmailcom.vercel.app
aacc-scales.vercel.app
aacc-scales-aaronccasanova-gmailcom.vercel.app
ba4b49f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
aacc-next-ts – ./recipes/next-ts
aacc-next-ts.vercel.app
aacc-next-ts-git-main-aaronccasanova-gmailcom.vercel.app
aacc-next-ts-aaronccasanova-gmailcom.vercel.app
ba4b49f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
aacc-next-ts-styled-comps – ./recipes/next-ts-styled-comps
aacc-next-ts-styled-comps.vercel.app
aacc-next-ts-styled-comps-aaronccasanova-gmailcom.vercel.app
aacc-next-ts-styled-comps-git-main-aaronccasanova-gmailcom.vercel.app