Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit 300f025

Browse files
authored
feat(packages): ✨ Add snippets related to extension (#33)
1 parent e3b2c17 commit 300f025

23 files changed

+528
-18
lines changed

.changeset/good-ears-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@terminal-nerds/snippets-extension": minor
3+
---
4+
5+
✨ Added a module `schema` for extension snippets.

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ Reusable pieces of code, which can be **reused** across the projects.
9696
> Package names are prefixed with `snippets-`.\
9797
> As in: `@terminal-nerds/snippets-<package name>`
9898
99-
| Name | Version |
100-
| ----------------------------- | ---------------------------------------------- |
101-
| [![snippets badge]][snippets] | [![snippets version badge]][snippets npm page] |
102-
| <!-- PACKAGES --> | <!-- PACKAGES --> |
103-
| [![error badge]][error] | [![error version badge]][error npm page] |
104-
| [![regexp badge]][regexp] | [![regexp version badge]][regexp npm page] |
105-
| [![runtime badge]][runtime] | [![runtime version badge]][runtime npm page] |
106-
| [![string badge]][string] | [![string version badge]][string npm page] |
107-
| [![test badge]][test] | [![test version badge]][test npm page] |
108-
| [![type badge]][type] | [![type version badge]][type npm page] |
99+
| Name | Version |
100+
| ------------------------------- | ------------------------------------------------ |
101+
| [![snippets badge]][snippets] | [![snippets version badge]][snippets npm page] |
102+
| <!-- PACKAGES --> | <!-- PACKAGES --> |
103+
| [![extension badge]][extension] | [![extension version badge]][extension npm page] |
104+
| [![error badge]][error] | [![error version badge]][error npm page] |
105+
| [![regexp badge]][regexp] | [![regexp version badge]][regexp npm page] |
106+
| [![runtime badge]][runtime] | [![runtime version badge]][runtime npm page] |
107+
| [![string badge]][string] | [![string version badge]][string npm page] |
108+
| [![test badge]][test] | [![test version badge]][test npm page] |
109+
| [![type badge]][type] | [![type version badge]][type npm page] |
109110

110111
[snippets]: ./packages/snippets/README.md
111112
[snippets badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets&style=flat-square&color=informational
@@ -114,6 +115,11 @@ Reusable pieces of code, which can be **reused** across the projects.
114115

115116
<!-- prettier-ignore-start -->
116117
<!-- PACKAGES LINKS -->
118+
[extension]: ./packages/extension/README.md
119+
[extension badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-extension&style=flat-square&color=informational
120+
[extension version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-extension/latest?style=flat-square&logo=npm
121+
[extension npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-extension
122+
117123
[error]: ./packages/error/README.md
118124
[error badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-error&style=flat-square&color=informational
119125
[error version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-error/latest?style=flat-square&logo=npm

packages/extension/.depcheckrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ignores": ["@terminal-nerds/*-config", "tsup", "vitest"]
3+
}

packages/extension/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @terminal-nerds/snippets-extension<!-- markdownlint-disable line-length list-marker-space no-duplicate-header ul-style ul-indent no-bare-urls -->

packages/extension/LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/xeho91/Nextcloud/Projects/terminal-nerds/snippets/LICENSE.md

packages/extension/README.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# @terminal-nerds/snippets-extension
2+
3+
![package version badge]
4+
[![size badge]][size url]
5+
[![dependencies badge]][dependencies url]
6+
7+
➡️ **This package wraps all available modules with snippets related to extension**
8+
— part of the [terminal-nerds/snippets] project.
9+
10+
[terminal-nerds/snippets]: https://github.com/terminal-nerds/snippets
11+
[package version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-extension/latest?style=for-the-badge&logo=npm
12+
[dependencies badge]: https://img.shields.io/librariesio/release/npm/@terminal-nerds/snippets-extension?style=for-the-badge
13+
[dependencies url]: https://libraries.io/npm/@terminal-nerds%2snippets-extension
14+
[size badge]: https://img.shields.io/bundlephobia/minzip/@terminal-nerds/snippets-extension?style=for-the-badge&label=size
15+
[size url]: https://packagephobia.com/result?p=@terminal-nerds/snippets-extension
16+
17+
## Modules included
18+
19+
[![documentation badge]][documentation url]
20+
21+
[documentation badge]: https://img.shields.io/static/v1?color=informational&style=for-the-badge&label=documentation&message=jsdocs.io
22+
[documentation url]: https://jsdocs.io/package/@terminal-nerds/snippets-extension
23+
24+
<!-- prettier-sort-markdown-table -->
25+
26+
| Name | Size |
27+
| --------------------------------------------- | ----------------------------------------------------- |
28+
| [`@terminal-nerds/snippets-extension/schema`] | ![schema size gzip badge] ![schema size brotli badge] |
29+
30+
<!-- prettier-ignore-start -->
31+
<!-- MODULES LINKS -->
32+
[`@terminal-nerds/snippets-extension/schema`]: https://github.com/terminal-nerds/snippets/blob/main/packages/extension/source/schema/schema.ts
33+
[schema size gzip badge]: https://badgen.net/badgesize/gzip/file-url/unpkg.com/@terminal-nerds/snippets-extension/dist/schema/schema.js?label=gzip
34+
[schema size brotli badge]: https://badgen.net/badgesize/brotli/file-url/unpkg.com/@terminal-nerds/snippets-extension/dist/schema/schema.js?label=brotli
35+
<!-- prettier-ignore-end -->
36+
37+
---
38+
39+
## Prerequisites & usage
40+
41+
### Optional
42+
43+
[![supported typescript version badge]][typescript]
44+
![types badge]
45+
46+
[typescript]: https://typescriptlang.org/
47+
[typescript icon]: https://api.iconify.design/logos/typescript-icon.svg
48+
[supported typescript version badge]: https://img.shields.io/github/package-json/dependency-version/terminal-nerds/snippets/peer/typescript?filename=packages%2Ftypescript%2Fpackage.json&logo=typescript&style=for-the-badge&label=typescript
49+
[types badge]: https://img.shields.io/npm/types/@terminal-nerds/snippets-extension?style=for-the-badge&logo=typescript
50+
51+
If you are using ![typescript icon] [TypeScript],
52+
the latest version, which supports new features _(such as `satisfies`)_, is supported.
53+
54+
### Runtime environments
55+
56+
This package can be used in several runtime environments.
57+
We aim for cross-runtime compatibility and ensure proper error messages
58+
if a particular snippet cannot be run in the currently running environment.
59+
60+
#### Browsers
61+
62+
We use [browserslist] to define the minimum browsers versions supported.\
63+
Take a look at our [shared browserslist configuration] for more details.
64+
65+
[browserslist]: https://github.com/browserslist/browserslist
66+
[shared browserslist configuration]: https://github.com/terminal-nerds/configs/blob/main/packages/browserslist/source/browsers.ts
67+
68+
**Usage**:
69+
70+
```html
71+
<script type="module">
72+
import { snippet } from "https://cdn.jsdelivr.net/npm/@terminal-nerds/snippets-extension";
73+
</script>
74+
```
75+
76+
---
77+
78+
#### Bun
79+
80+
We aim to support the latest version of ![bun icon] [bun].
81+
82+
**Usage**:
83+
84+
Firstly, install it:
85+
86+
```sh
87+
bun add @terminal-nerds/snippets-extension
88+
```
89+
90+
And then in a particular file:
91+
92+
```js
93+
import { snippet } from "@terminal-nerds/snippets-extension";
94+
```
95+
96+
[bun]: https://bun.sh/
97+
[bun icon]: https://api.iconify.design/logos/bun.svg
98+
99+
---
100+
101+
#### Deno
102+
103+
We aim to support the latest version of ![deno icon] [Deno].
104+
105+
**Usage**:
106+
107+
```ts
108+
import { snippet } from "npm:@terminal-nerds/snippets-extension";
109+
```
110+
111+
[deno]: https://deno.land/
112+
[deno icon]: https://api.iconify.design/logos/deno.svg
113+
114+
---
115+
116+
#### Node.js
117+
118+
[![node.js version support badge]][node.js]
119+
120+
The latest ![node.js icon] [Node.js] LTS _(Long-Term Support)_ version is the minimum one supported.
121+
122+
> **Warning**\
123+
> **This package is written in [ES Module] _(ESM)_ type.**\
124+
> So, if you wish to use it in a project with CommonJS (CJS) type, you need to bundle this package or a particular module(s).
125+
126+
**Usage**:
127+
128+
Install it first with the Node.js package manager of your choice. In our example, we use [pnpm].
129+
130+
```sh
131+
pnpm add @terminal-nerds/snippets-extension
132+
```
133+
134+
And then in a particular file:
135+
136+
```js
137+
import { snippet } from "@terminal-nerds/snippets-extension";
138+
```
139+
140+
[ES Module]: https://www.freecodecamp.org/news/javascript-es-modules-and-module-bundlers
141+
[pnpm]: https://pnpm.io
142+
[node.js]: https://nodejs.org/en/
143+
[node.js icon]: https://api.iconify.design/logos/nodejs-icon.svg
144+
[node.js version support badge]: https://img.shields.io/node/v-lts/@terminal-nerds/snippets?style=for-the-badge&logo=nodedotjs
145+
146+
---
147+
148+
## Security
149+
150+
[![workflow security badge]][security policy]
151+
152+
🔐 For more information, please refer to the [Security section] at the root of
153+
the [terminal-nerds/snippets] monorepo.
154+
155+
[workflow security badge]: https://img.shields.io/github/actions/workflow/status/terminal-nerds/snippets/maintenance.yml?label=Security&logo=github&style=for-the-badge&branch=main
156+
[security section]: https://github.com/terminal-nerds/snippets#security
157+
[security policy]: https://github.com/terminal-nerds/snippets/security/policy
158+
159+
---
160+
161+
## License
162+
163+
[![license badge]][license]
164+
165+
⚖️ For more information, please refer to the [License section] at the root of the [terminal-nerds/snippets] monorepo.
166+
167+
[license]: https://github.com/terminal-nerds/snippets/blob/main/LICENSE.md
168+
[license badge]: https://img.shields.io/github/license/terminal-nerds/snippets?style=for-the-badge
169+
[license section]: https://github.com/terminal-nerds/snippets#License
170+
171+
### Contributing
172+
173+
[![contributors badge]][contributors url]
174+
175+
🤝 **Contributions of any kind are welcome!**
176+
177+
Please refer to the monorepo _([terminal-nerds/snippets])_ project's [CONTRIBUTING file] for more information
178+
if you wish to get involved.
179+
180+
[contributing file]: https://github.com/terminal-nerds/snippets/blob/main/.github/CONTRIBUTING.md
181+
[contributors badge]: https://img.shields.io/github/contributors/terminal-nerds/snippets?style=for-the-badge
182+
[contributors url]: https://github.com/terminal-nerds/snippets#contributors
183+
184+
### Author
185+
186+
🎉 The idea of this project was initiated by [xeho91]. However, it's the [contributors] who matter the most.
187+
188+
[contributors]: https://github.com/terminal-nerds/snippets/blob/main/README.md#project-contributors
189+
[xeho91]: https://github.com/xeho91

packages/extension/package.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"$schema": "https://json.schemastore.org/package",
3+
"type": "module",
4+
"name": "@terminal-nerds/snippets-extension",
5+
"version": "0.0.0",
6+
"description": "@terminal-nerds reusable snippets for extensions.",
7+
"keywords": [
8+
"snippets",
9+
"typescript",
10+
"extension"
11+
],
12+
"license": "MIT",
13+
"author": {
14+
"name": "Mateusz Kadlubowski",
15+
"email": "[email protected]",
16+
"url": "https://xeho91.com"
17+
},
18+
"homepage": "https://github.com/terminal-nerds/snippets",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/terminal-nerds/snippets.git",
22+
"directory": "packages/extension"
23+
},
24+
"bugs": "https://github.com/terminal-nerds/snippets/issues",
25+
"engines": {
26+
"node": ">=18"
27+
},
28+
"exports": {
29+
".": {
30+
"types": "./dist/main.d.ts",
31+
"import": "./dist/main.js"
32+
},
33+
"./*": {
34+
"types": "./dist/*/*.d.ts",
35+
"import": "./dist/*/*.js"
36+
},
37+
"./schema/*": {
38+
"types": "./dist/schema/groups/*.d.ts",
39+
"import": "./dist/schema/groups/*.js"
40+
}
41+
},
42+
"files": [
43+
"dist/"
44+
],
45+
"scripts": {
46+
"build": "tsup",
47+
"clean": "concurrently \"pnpm:clean:*\" --group --timings",
48+
"clean:build": "del \"./dist\"",
49+
"clean:cache": "del \"./node_modules/.cache\"",
50+
"clean:test": "del \"./coverage\"",
51+
"dev:test": "vitest watch --ui",
52+
"dev:pkg": "tsup --watch",
53+
"fix": "concurrently \"pnpm:fix:*\" --group --timings",
54+
"fix:format": "pretty-quick --branch main --pattern \"packages/extension/**/*\" --verbose",
55+
"fix:js": "pnpm lint:js --fix",
56+
"fix:md": "pnpm lint:md --fix",
57+
"fix:pkg": "syncpack format ; syncpack fix-mismatches",
58+
"lint": "concurrently \"pnpm:lint:*\" --group --timings",
59+
"lint:deps": "depcheck",
60+
"lint:format": "pnpm fix:format --check",
61+
"lint:js": "DEBUG=\"eslint:cli-engine\" eslint . --ext .cjs,.js,.ts,.json,.yml --cache --cache-location \"./node_modules/.cache/eslint\"",
62+
"lint:md": "markdownlint . --config \"../../.markdownlint.json\" --dot --ignore \"./LICENSE.md\" --ignore-path \"../../.gitignore\"",
63+
"lint:pkg": "syncpack list-mismatches",
64+
"lint:types": "tsc --noEmit",
65+
"test:unit": "vitest run --dir \"./source\""
66+
},
67+
"peerDependencies": {
68+
"typescript": "4.9.5"
69+
},
70+
"dependencies": {
71+
"zod": "3.20.6"
72+
},
73+
"devDependencies": {
74+
"@terminal-nerds/snippets-test": "workspace:*"
75+
},
76+
"peerDependenciesMeta": {
77+
"typescript": {
78+
"optional": true
79+
}
80+
}
81+
}

packages/extension/source/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* MODULES */
2+
export * from "./schema/schema.js";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { z } from "zod";
2+
3+
export const HTML_EXTENSIONS = ["html", "htm"] as const;
4+
export type HTMLExtension = (typeof HTML_EXTENSIONS)[number];
5+
export const HTML_EXTENSION_SCHEMA = z.enum(HTML_EXTENSIONS);
6+
7+
export function isHTMLExtension(extension: string): extension is HTMLExtension {
8+
return HTML_EXTENSION_SCHEMA.safeParse(extension).success;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { z } from "zod";
2+
3+
export const JAVASCRIPT_EXTENSIONS = ["cjs", "js", "jsx", "mjs"] as const;
4+
export type JavaScriptExtension = (typeof JAVASCRIPT_EXTENSIONS)[number];
5+
export const JAVASCRIPT_EXTENSION_SCHEMA = z.enum(JAVASCRIPT_EXTENSIONS);
6+
7+
export function isJavaScriptExtension(extension: string): extension is JavaScriptExtension {
8+
return JAVASCRIPT_EXTENSION_SCHEMA.safeParse(extension).success;
9+
}

0 commit comments

Comments
 (0)