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

Commit 82e822d

Browse files
authored
feat(packages): ✨ Add snippets related to runtime (#29)
1 parent f037f45 commit 82e822d

28 files changed

+1503
-17
lines changed

.changeset/early-pets-return.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@terminal-nerds/snippets-runtime": minor
3+
---
4+
5+
✨ Added a module `scope` for grouped snippets. It includes:
6+
7+
- `CI_CD_ENVIRONMENT_VARIABLES`
8+
- `type CICDEnvironmentVariable`
9+
- `CI_CD_ENVIRONMENT_VARIABLE_SCHEMA`
10+
- `type TestEnvironmentVariable`
11+
- `TEST_ENVIRONMENT_VARIABLES`
12+
- `TEST_ENVIRONMENT_VARIABLE_SCHEMA`
13+
- `inContinuousIntegration()`
14+
- `inTest()`

.changeset/kind-moons-flash.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"@terminal-nerds/snippets-runtime": minor
3+
---
4+
5+
✨ Added a module `environment` for grouped snippets. It includes:
6+
7+
- `RUNTIME_ENVIROMENTS`
8+
- `type RuntimeEnvironment`
9+
- `RUNTIME_ENVIROMENT_SCHEMA`
10+
- `IN_BROWSER`
11+
- `IN_BUN`
12+
- `IN_DENO`
13+
- `IN_DOM`
14+
- `IN_EDGE_RUNTIME`
15+
- `IN_HAPPY_DOM`
16+
- `IN_JSDOM`
17+
- `IN_WEB_WORKER`
18+
- `getRuntimeEnvironmentName()`
19+
- `validateRuntimeEnvironmentName()`
20+
- `isValidRuntimeEnvironmentName()`

.changeset/real-wolves-study.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@terminal-nerds/snippets-runtime": minor
3+
---
4+
5+
✨ Added a module `variable` for grouped snippets. It includes:
6+
7+
- `getEnvironmentVariables()`
8+
- `hasEnvironmentVariable()`
9+
- `getEnvironmentVariable()`
10+
- `setEnvironmentVariable()`
11+
- `deleteEnvironmentVariable()`

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Reusable pieces of code, which can be **reused** across the projects.
102102
| <!-- PACKAGES --> | <!-- PACKAGES --> |
103103
| [![error badge]][error] | [![error version badge]][error npm page] |
104104
| [![regexp badge]][regexp] | [![regexp version badge]][regexp npm page] |
105+
| [![runtime badge]][runtime] | [![runtime version badge]][runtime npm page] |
105106
| [![string badge]][string] | [![string version badge]][string npm page] |
106107
| [![test badge]][test] | [![test version badge]][test npm page] |
107108

@@ -127,6 +128,11 @@ Reusable pieces of code, which can be **reused** across the projects.
127128
[regexp version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-regexp/latest?style=flat-square&logo=npm
128129
[regexp npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-regexp
129130

131+
[runtime]: ./packages/runtime/README.md
132+
[runtime badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-runtime&style=flat-square&color=informational
133+
[runtime version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-runtime/latest?style=flat-square&logo=npm
134+
[runtime npm page]: https://www.npmjs.com/package/@terminal-nerds/snippets-runtime
135+
130136
[string]: ./packages/string/README.md
131137
[string badge]: https://img.shields.io/static/v1?label=%40terminal-nerds&message=snippets-string&style=flat-square&color=informational
132138
[string version badge]: https://img.shields.io/npm/v/@terminal-nerds/snippets-string/latest?style=flat-square&logo=npm

packages/error/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
"dependencies": {
6464
"modern-errors": "5.5.1",
65-
"zod": "3.21.0"
65+
"zod": "3.20.6"
6666
},
6767
"devDependencies": {
6868
"@terminal-nerds/snippets-test": "workspace:*"

packages/runtime/.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/runtime/CHANGELOG.md

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

packages/runtime/LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE.md

packages/runtime/README.md

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

packages/runtime/package.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"$schema": "https://json.schemastore.org/package",
3+
"type": "module",
4+
"name": "@terminal-nerds/snippets-runtime",
5+
"version": "0.0.0",
6+
"description": "@terminal-nerds reusable snippets for runtime.",
7+
"keywords": [
8+
"snippets",
9+
"typescript",
10+
"runtime"
11+
],
12+
"author": {
13+
"name": "Mateusz Kadlubowski",
14+
"email": "[email protected]",
15+
"url": "https://xeho91.com"
16+
},
17+
"license": "MIT",
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/runtime"
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+
},
38+
"files": [
39+
"dist/"
40+
],
41+
"scripts": {
42+
"build": "tsup",
43+
"clean": "concurrently \"pnpm:clean:*\" --group --timings",
44+
"clean:build": "del \"./dist\"",
45+
"clean:cache": "del \"./node_modules/.cache\"",
46+
"clean:test": "del \"./coverage\"",
47+
"dev:test": "vitest watch --ui",
48+
"dev:pkg": "tsup --watch",
49+
"fix": "concurrently \"pnpm:fix:*\" --group --timings",
50+
"fix:format": "pretty-quick --branch main --pattern \"packages/runtime/**/*\" --verbose",
51+
"fix:js": "pnpm lint:js --fix",
52+
"fix:md": "pnpm lint:md --fix",
53+
"fix:pkg": "syncpack format ; syncpack fix-mismatches",
54+
"lint": "concurrently \"pnpm:lint:*\" --group --timings",
55+
"lint:deps": "depcheck",
56+
"lint:format": "pnpm fix:format --check",
57+
"lint:js": "DEBUG=\"eslint:cli-engine\" eslint . --ext .cjs,.js,.ts,.json,.yml --cache --cache-location \"./node_modules/.cache/eslint\"",
58+
"lint:md": "markdownlint . --config \"../../.markdownlint.json\" --dot --ignore \"./LICENSE.md\" --ignore-path \"../../.gitignore\"",
59+
"lint:pkg": "syncpack list-mismatches",
60+
"lint:types": "tsc --noEmit"
61+
},
62+
"peerDependencies": {
63+
"typescript": "4.9.5"
64+
},
65+
"dependencies": {
66+
"@terminal-nerds/snippets-error": "workspace:*",
67+
"zod": "3.20.6"
68+
},
69+
"peerDependenciesMeta": {
70+
"typescript": {
71+
"optional": true
72+
}
73+
},
74+
"devDependencies": {
75+
"@terminal-nerds/snippets-test": "workspace:*",
76+
"@edge-runtime/vm": "2.1.2",
77+
"happy-dom": "8.9.0",
78+
"jsdom": "21.1.0"
79+
}
80+
}

0 commit comments

Comments
 (0)