@mrmartineau/kit 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +284 -67
- package/package.json +40 -17
- package/src/biome/biome.json +37 -7
- package/src/biome/strict.json +108 -0
- package/src/eslint/index.ts +49 -13
- package/src/index.ts +2 -2
- package/src/oxfmt/.oxfmtrc.json +5 -1
- package/src/oxlint/.oxlintrc.json +12 -3
- package/src/oxlint/strict.json +61 -0
- package/src/prettier/astro.js +31 -0
- package/src/prettier/astro.test.ts +48 -0
- package/src/sounds/index.ts +156 -156
- package/src/utils/checks/checks.test.ts +162 -0
- package/src/utils/checks/collections.ts +63 -0
- package/src/utils/checks/index.ts +17 -0
- package/src/utils/checks/isEmpty.ts +15 -0
- package/src/utils/checks/nullish.ts +26 -0
- package/src/utils/checks/numbers.ts +31 -0
- package/src/utils/checks/objects.ts +38 -0
- package/src/utils/checks/primitives.ts +41 -0
- package/src/utils/formatters/constants.ts +1 -1
- package/src/utils/formatters/index.ts +24 -24
- package/src/utils/formatters/numbers/__tests__/formatNumberBase.test.ts +33 -46
- package/src/utils/formatters/numbers/__tests__/formatNumberCurrency.test.ts +42 -43
- package/src/utils/formatters/numbers/__tests__/formatNumberDecimal.test.ts +43 -56
- package/src/utils/formatters/numbers/__tests__/formatNumberDecimalForceDecimalPlaces.test.ts +23 -34
- package/src/utils/formatters/numbers/formatNumberAccounting.ts +7 -7
- package/src/utils/formatters/numbers/formatNumberBase.ts +11 -11
- package/src/utils/formatters/numbers/formatNumberBytes.ts +13 -13
- package/src/utils/formatters/numbers/formatNumberCompact.ts +5 -5
- package/src/utils/formatters/numbers/formatNumberCurrency.ts +6 -6
- package/src/utils/formatters/numbers/formatNumberDecimal.ts +5 -5
- package/src/utils/formatters/numbers/formatNumberDecimalForceDecimalPlaces.ts +4 -4
- package/src/utils/formatters/numbers/formatNumberOrdinal.ts +13 -16
- package/src/utils/formatters/numbers/formatNumberPercent.ts +5 -5
- package/src/utils/formatters/numbers/formatNumberRange.ts +5 -5
- package/src/utils/formatters/numbers/formatNumberSignDisplay.ts +6 -6
- package/src/utils/formatters/strings/formatInitials.ts +2 -2
- package/src/utils/formatters/strings/formatList.test.ts +48 -51
- package/src/utils/formatters/strings/formatList.ts +4 -4
- package/src/utils/formatters/strings/maskString.ts +12 -15
- package/src/utils/formatters/strings/normalizeWhitespace.ts +1 -1
- package/src/utils/formatters/strings/pluralize.ts +3 -7
- package/src/utils/formatters/strings/slugify.ts +3 -3
- package/src/utils/formatters/strings/splitWords.ts +5 -5
- package/src/utils/formatters/strings/stripDiacritics.ts +1 -1
- package/src/utils/formatters/strings/toCamelCase.ts +7 -7
- package/src/utils/formatters/strings/toKebabCase.ts +2 -2
- package/src/utils/formatters/strings/toPascalCase.ts +4 -4
- package/src/utils/formatters/strings/toSnakeCase.ts +2 -2
- package/src/utils/formatters/strings/toStartCase.test.ts +40 -45
- package/src/utils/formatters/strings/toStartCase.ts +4 -4
- package/src/utils/formatters/strings/truncate.ts +11 -15
- package/src/utils/index.ts +2 -1
package/README.md
CHANGED
|
@@ -8,17 +8,22 @@ A personal collection of sounds, utilities, components, and hooks for use across
|
|
|
8
8
|
bun add @mrmartineau/kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
This package provides **configuration files and static assets only
|
|
11
|
+
This package provides **configuration files and static assets only**, with no runtime dependencies — it does not install the underlying tools. Install whichever tools you actually need in your project:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
#
|
|
15
|
-
bun add -d @biomejs/biome
|
|
16
|
-
|
|
17
|
-
# oxc (linter + formatter)
|
|
14
|
+
# oxc (linter + formatter) — the default for new projects
|
|
18
15
|
bun add -d oxlint oxfmt
|
|
16
|
+
# …plus, in an Astro project, so oxfmt can format .astro files
|
|
17
|
+
bun add -d @astrojs/compiler-rs
|
|
18
|
+
|
|
19
|
+
# Biome (linter + formatter) — older projects
|
|
20
|
+
bun add -d @biomejs/biome
|
|
19
21
|
|
|
20
22
|
# ESLint + Prettier
|
|
21
|
-
bun add -d eslint prettier
|
|
23
|
+
bun add -d eslint @eslint/js prettier
|
|
24
|
+
|
|
25
|
+
# Prettier with .astro support
|
|
26
|
+
bun add -d prettier prettier-plugin-astro
|
|
22
27
|
```
|
|
23
28
|
|
|
24
29
|
You don't need all of them — just pick the tools you want to use and reference the matching config from this package.
|
|
@@ -59,12 +64,7 @@ audio.play()
|
|
|
59
64
|
**Use the metadata module for programmatic access:**
|
|
60
65
|
|
|
61
66
|
```ts
|
|
62
|
-
import {
|
|
63
|
-
sounds,
|
|
64
|
-
soundCategories,
|
|
65
|
-
getSoundsByCategory,
|
|
66
|
-
getSoundPath,
|
|
67
|
-
} from '@mrmartineau/kit/sounds'
|
|
67
|
+
import { sounds, soundCategories, getSoundsByCategory, getSoundPath } from '@mrmartineau/kit/sounds'
|
|
68
68
|
|
|
69
69
|
// List all sound names
|
|
70
70
|
console.log(sounds)
|
|
@@ -78,18 +78,35 @@ const clickSounds = getSoundsByCategory('click')
|
|
|
78
78
|
|
|
79
79
|
### Biome
|
|
80
80
|
|
|
81
|
-
Shared [Biome](https://biomejs.dev) config for linting and formatting.
|
|
81
|
+
Shared [Biome](https://biomejs.dev) config for linting and formatting. New projects
|
|
82
|
+
use oxlint and oxfmt instead; this config stays for projects that still use Biome. Biome natively supports extending from packages via its `extends` field.
|
|
82
83
|
|
|
83
84
|
In your project's `biome.json`:
|
|
84
85
|
|
|
85
86
|
```json
|
|
86
87
|
{
|
|
87
|
-
"$schema": "https://biomejs.dev/schemas/2.
|
|
88
|
+
"$schema": "https://biomejs.dev/schemas/2.5.7/schema.json",
|
|
88
89
|
"extends": ["./node_modules/@mrmartineau/kit/src/biome/biome.json"]
|
|
89
90
|
}
|
|
90
91
|
```
|
|
91
92
|
|
|
92
|
-
**Included settings:** space indentation, single quotes, no semicolons,
|
|
93
|
+
**Included settings:** space indentation (2), single quotes, no semicolons, trailing commas, 100 line width, import sorting, recommended lint rules, React domain rules.
|
|
94
|
+
|
|
95
|
+
The config is marked `"root": false` so Biome doesn't mistake it for a second root
|
|
96
|
+
configuration when it sits inside a project. `root` is not inherited through
|
|
97
|
+
`extends`, so your own `biome.json` stays the root.
|
|
98
|
+
|
|
99
|
+
It also turns off the unused-import, unused-variable, `useConst` and
|
|
100
|
+
`useImportType` rules in `.astro`, `.svelte` and `.vue` files. Biome cannot see
|
|
101
|
+
what the template uses, so it reports false errors, and `biome check --write`
|
|
102
|
+
deletes imports the template needs.
|
|
103
|
+
|
|
104
|
+
> Biome **replaces** the `overrides` list you extend; it does not add to it. If
|
|
105
|
+
> your `biome.json` has its own `overrides`, copy the kit ones you still need.
|
|
106
|
+
|
|
107
|
+
> Object-key sorting (`assist.actions.source.useSortedKeys`) is deliberately
|
|
108
|
+
> **not** enabled — it rewrites object literals in your source on save, which is
|
|
109
|
+
> surprising and occasionally meaningful. Turn it on per-project if you want it.
|
|
93
110
|
|
|
94
111
|
### oxlint
|
|
95
112
|
|
|
@@ -97,42 +114,133 @@ Shared [oxlint](https://oxc.rs/docs/guide/usage/linter/config) config. Reference
|
|
|
97
114
|
|
|
98
115
|
```json
|
|
99
116
|
{
|
|
100
|
-
"$schema": "
|
|
117
|
+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
|
|
101
118
|
"extends": ["./node_modules/@mrmartineau/kit/src/oxlint/.oxlintrc.json"]
|
|
102
119
|
}
|
|
103
120
|
```
|
|
104
121
|
|
|
105
|
-
**Included settings:** correctness (error), suspicious + perf (warn), typescript/unicorn/import/react/jsx-a11y plugins, no-console warn, no-debugger error.
|
|
122
|
+
**Included settings:** correctness (error), suspicious + perf (warn), browser + node + es2024 envs, typescript/unicorn/import/react/jsx-a11y plugins, no-console warn, no-debugger error, `typescript/consistent-type-imports` error, `no-unused-vars` that allows `const { a, ...rest } = x`, `react/react-in-jsx-scope` off (React 17+ needs no `React` import).
|
|
123
|
+
|
|
124
|
+
`consistent-type-imports` pairs with the `verbatimModuleSyntax` TypeScript
|
|
125
|
+
setting this kit also uses: without it, a type-only import that's missing the
|
|
126
|
+
`type` keyword survives into the emitted JavaScript as a real runtime import.
|
|
106
127
|
|
|
107
128
|
### oxfmt
|
|
108
129
|
|
|
109
|
-
Shared [oxfmt](https://oxc.rs/docs/guide/usage/formatter) config.
|
|
130
|
+
Shared [oxfmt](https://oxc.rs/docs/guide/usage/formatter) config. oxfmt has no
|
|
131
|
+
`extends`, but it reads an `oxfmt.config.ts`, so import the kit settings and add
|
|
132
|
+
your own:
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
// oxfmt.config.ts
|
|
136
|
+
import kit from '@mrmartineau/kit/oxfmt' with { type: 'json' }
|
|
110
137
|
|
|
111
|
-
|
|
112
|
-
oxfmt -c ./node_modules/@mrmartineau/kit/src/oxfmt/.oxfmtrc.json
|
|
138
|
+
export default { ...kit, ignorePatterns: ['src/routeTree.gen.ts'] }
|
|
113
139
|
```
|
|
114
140
|
|
|
115
|
-
|
|
141
|
+
The settings match the Biome config: single quotes, no semicolons, 2-space
|
|
142
|
+
indentation, 100 print width, import sorting with no blank lines between groups.
|
|
143
|
+
`astro: true` formats `.astro` files, templates included, when the project has
|
|
144
|
+
`@astrojs/compiler-rs` installed. Projects without Astro files do not need it.
|
|
145
|
+
|
|
146
|
+
### Strict configs
|
|
147
|
+
|
|
148
|
+
`src/biome/strict.json` and `src/oxlint/strict.json` extend the base configs
|
|
149
|
+
and turn the [coding standards](https://github.com/mrmartineau/agent-skills/tree/main/skills/coding-standards)
|
|
150
|
+
into errors. An agent cannot hand-wave a lint error, so it has one way left to
|
|
151
|
+
write the code: the standard one. Use them in new projects. In an older project,
|
|
152
|
+
turn on rules one at a time.
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{ "extends": ["./node_modules/@mrmartineau/kit/src/biome/strict.json"] }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{ "extends": ["./node_modules/@mrmartineau/kit/src/oxlint/strict.json"] }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Some files must break a rule: a package's entry `index.ts` re-exports, and
|
|
163
|
+
Storybook stories or Next.js pages need a default export. Turn the rule off for
|
|
164
|
+
those files only. In oxlint, your `overrides` add to the strict ones:
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"extends": ["./node_modules/@mrmartineau/kit/src/oxlint/strict.json"],
|
|
169
|
+
"overrides": [
|
|
170
|
+
{ "files": ["src/index.ts"], "rules": { "oxc/no-barrel-file": "off" } },
|
|
171
|
+
{ "files": ["**/*.stories.tsx"], "rules": { "import/no-default-export": "off" } }
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
In Biome, your `overrides` replace the strict ones, so copy those first
|
|
177
|
+
(see [Biome](#biome)).
|
|
178
|
+
|
|
179
|
+
| Standard | Biome | oxlint |
|
|
180
|
+
| :------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- |
|
|
181
|
+
| kebab-case file names | `useFilenamingConvention` | `unicorn/filename-case` |
|
|
182
|
+
| No barrel files | `noBarrelFile`, `noReExportAll` | `oxc/no-barrel-file` |
|
|
183
|
+
| Named exports (config files excepted) | `noDefaultExport` | `import/no-default-export` |
|
|
184
|
+
| No `import * as` | `noNamespaceImport` | `import/no-namespace` |
|
|
185
|
+
| ES modules only | `noCommonJs` | `typescript/no-require-imports` |
|
|
186
|
+
| `interface` for object shapes | `useConsistentTypeDefinitions` | `typescript/consistent-type-definitions` |
|
|
187
|
+
| Unions, not enums | `noEnum` | — (use `erasableSyntaxOnly` in `tsconfig.json`) |
|
|
188
|
+
| No `any`, no `!`, no `@ts-ignore` | `noExplicitAny`, `noNonNullAssertion`, `noTsIgnore` | `typescript/no-explicit-any`, `typescript/no-non-null-assertion`, `typescript/ban-ts-comment` |
|
|
189
|
+
| `import type` for types | `useImportType` | `typescript/consistent-type-imports` (base) |
|
|
190
|
+
| At most 3 parameters | `useMaxParams` | `max-params` |
|
|
191
|
+
| No nested ternaries, no `==` | `noNestedTernary`, `noDoubleEquals` | `no-nested-ternary`, `eqeqeq` |
|
|
192
|
+
| Only `console.warn` and `console.error` | `noConsole` | `no-console` |
|
|
193
|
+
| No silent empty `catch` (a comment is fine) | `noEmptyBlockStatements` | `no-empty` |
|
|
194
|
+
| Sorting: Biome wants a compare function; oxlint wants `toSorted()` and `toReversed()` when the result is used | `useArraySortCompare` | `unicorn/no-array-sort`, `unicorn/no-array-reverse` |
|
|
195
|
+
| React: no `key={index}`, no components in components, hooks at top level | `noArrayIndexKey`, `noNestedComponentDefinitions`, `useHookAtTopLevel` | `react/no-array-index-key`, `react/no-unstable-nested-components`, `react/rules-of-hooks` |
|
|
196
|
+
| No `dangerouslySetInnerHTML`; for sanitised HTML, turn the rule off on that line with a reason | `noDangerouslySetInnerHtml` (base) | `react/no-danger` |
|
|
197
|
+
|
|
198
|
+
When an agent breaks a standard that has no rule here, add one. GritQL
|
|
199
|
+
plugins (Biome) and JS plugins (oxlint) cover what the built-in rules cannot.
|
|
116
200
|
|
|
117
201
|
### ESLint
|
|
118
202
|
|
|
119
|
-
Shared [ESLint](https://eslint.org) flat config with
|
|
203
|
+
Shared [ESLint](https://eslint.org) flat config with a small set of base rules.
|
|
204
|
+
It carries no formatting rules — use Prettier, Biome or oxfmt for that.
|
|
120
205
|
|
|
121
|
-
|
|
206
|
+
This config **layers on top of a recommended base rather than replacing it**, so
|
|
207
|
+
that this package stays dependency-free. Compose it with `@eslint/js` yourself —
|
|
208
|
+
on its own it will not give you `no-unused-vars`, `no-undef` and friends:
|
|
122
209
|
|
|
123
210
|
```ts
|
|
124
|
-
import
|
|
211
|
+
import js from '@eslint/js'
|
|
212
|
+
import kit from '@mrmartineau/kit/eslint'
|
|
125
213
|
import { defineConfig } from 'eslint/config'
|
|
126
214
|
|
|
127
215
|
export default defineConfig([
|
|
216
|
+
js.configs.recommended,
|
|
128
217
|
{
|
|
129
218
|
files: ['**/*.{ts,tsx,js,jsx}'],
|
|
130
|
-
extends: [
|
|
219
|
+
extends: [...kit],
|
|
131
220
|
},
|
|
132
221
|
])
|
|
133
222
|
```
|
|
134
223
|
|
|
135
|
-
**Included rules:** prefer-const, no-var, no-console (warn), no-debugger
|
|
224
|
+
**Included rules:** prefer-const, no-var, no-console (warn), no-debugger
|
|
225
|
+
(error), no-alert (warn), eqeqeq, object-shorthand, prefer-template,
|
|
226
|
+
prefer-arrow-callback and curly (multi-line). Add your own TypeScript/React
|
|
227
|
+
plugins on top.
|
|
228
|
+
|
|
229
|
+
`curly` is the one stylistic-looking rule here, and it's deliberate: it guards
|
|
230
|
+
against a statement being accidentally added outside an unbraced block, which no
|
|
231
|
+
formatter will catch for you.
|
|
232
|
+
|
|
233
|
+
#### Opt-in: ban `../` imports
|
|
234
|
+
|
|
235
|
+
`no-restricted-imports` is exported separately rather than being on by default —
|
|
236
|
+
it only makes sense once a project has path aliases configured, and colocated
|
|
237
|
+
tests or sibling-directory imports in a library layout can't satisfy it at all.
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
import kit, { noRelativeParentImports } from '@mrmartineau/kit/eslint'
|
|
241
|
+
|
|
242
|
+
export default defineConfig([...kit, noRelativeParentImports])
|
|
243
|
+
```
|
|
136
244
|
|
|
137
245
|
### Prettier
|
|
138
246
|
|
|
@@ -152,6 +260,51 @@ Or create a `.prettierrc.json`:
|
|
|
152
260
|
|
|
153
261
|
**Included settings:** single quotes, no semicolons, 2-space indentation, trailing commas, 100 print width.
|
|
154
262
|
|
|
263
|
+
#### Astro
|
|
264
|
+
|
|
265
|
+
Prettier can't parse `.astro` files on its own, so there's a separate config that
|
|
266
|
+
layers [`prettier-plugin-astro`](https://github.com/withastro/prettier-plugin-astro)
|
|
267
|
+
on top of the base one. It's kept separate because Prettier hard-errors when a
|
|
268
|
+
plugin listed in `plugins` can't be resolved — putting the plugin in the base
|
|
269
|
+
config would break every non-Astro consumer.
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
bun add -d prettier prettier-plugin-astro
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
In your `package.json`:
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"prettier": "@mrmartineau/kit/prettier/astro"
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Or in a `prettier.config.mjs`:
|
|
284
|
+
|
|
285
|
+
```js
|
|
286
|
+
export { default } from '@mrmartineau/kit/prettier/astro'
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Everything from the base config still applies — the `.astro` frontmatter and
|
|
290
|
+
expressions are formatted with the same single quotes, no semicolons, 2-space
|
|
291
|
+
indentation and 100 print width.
|
|
292
|
+
|
|
293
|
+
If you also use `prettier-plugin-tailwindcss`, it must come **last** in
|
|
294
|
+
`plugins`, so extend the config rather than referencing it directly:
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
import astro from '@mrmartineau/kit/prettier/astro'
|
|
298
|
+
|
|
299
|
+
export default {
|
|
300
|
+
...astro,
|
|
301
|
+
plugins: [...astro.plugins, 'prettier-plugin-tailwindcss'],
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
> oxfmt also formats `.astro` files (see [oxfmt](#oxfmt)). Biome does not format
|
|
306
|
+
> Astro templates.
|
|
307
|
+
|
|
155
308
|
### Utils, Components, Hooks
|
|
156
309
|
|
|
157
310
|
```ts
|
|
@@ -196,53 +349,117 @@ import {
|
|
|
196
349
|
|
|
197
350
|
##### Number formatters
|
|
198
351
|
|
|
199
|
-
| Function | Signature
|
|
200
|
-
| --------------------------------------- |
|
|
201
|
-
| `formatNumberBase` | `(value, options?)`
|
|
202
|
-
| `formatNumberDecimal` | `(value, decimalCount = 2, options?)`
|
|
203
|
-
| `formatNumberDecimalForceDecimalPlaces` | `(value, decimalCount = 2, options?)`
|
|
204
|
-
| `formatNumberCurrency` | `(value, currency, decimalCount = 2, options?)`
|
|
205
|
-
| `formatNumberAccounting` | `(value, currency, decimalCount = 2, options?)` — negatives wrapped in parens
|
|
206
|
-
| `formatNumberPercent` | `(value, decimalCount = 2, options?)` — value already in decimal form (`0.42` → `42%`)
|
|
207
|
-
| `formatNumberCompact` | `(value, display = "short", options?)`
|
|
208
|
-
| `formatNumberOrdinal` | `(value, locale = "en-GB")`
|
|
209
|
-
| `formatNumberBytes` | `(bytes, binary = false, decimalCount = 2)`
|
|
210
|
-
| `formatNumberRange` | `(min, max, options?, locale = "en-GB")`
|
|
211
|
-
| `formatNumberSignDisplay` | `(value, decimalCount = 2, signDisplay = "exceptZero", options?)`
|
|
352
|
+
| Function | Signature | Example |
|
|
353
|
+
| --------------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
|
|
354
|
+
| `formatNumberBase` | `(value, options?)` | `formatNumberBase(1234)` → `"1,234"` |
|
|
355
|
+
| `formatNumberDecimal` | `(value, decimalCount = 2, options?)` | `formatNumberDecimal(1234.567, 2)` → `"1,234.57"` |
|
|
356
|
+
| `formatNumberDecimalForceDecimalPlaces` | `(value, decimalCount = 2, options?)` | `formatNumberDecimalForceDecimalPlaces(10, 2)` → `"10.00"` |
|
|
357
|
+
| `formatNumberCurrency` | `(value, currency, decimalCount = 2, options?)` | `formatNumberCurrency(1234, "GBP")` → `"£1,234.00"` |
|
|
358
|
+
| `formatNumberAccounting` | `(value, currency, decimalCount = 2, options?)` — negatives wrapped in parens | `formatNumberAccounting(-100, "USD")` → `"($100.00)"` |
|
|
359
|
+
| `formatNumberPercent` | `(value, decimalCount = 2, options?)` — value already in decimal form (`0.42` → `42%`) | `formatNumberPercent(0.421)` → `"42.1%"` |
|
|
360
|
+
| `formatNumberCompact` | `(value, display = "short", options?)` | `formatNumberCompact(1200)` → `"1.2K"` |
|
|
361
|
+
| `formatNumberOrdinal` | `(value, locale = "en-GB")` | `formatNumberOrdinal(3)` → `"3rd"` |
|
|
362
|
+
| `formatNumberBytes` | `(bytes, binary = false, decimalCount = 2)` | `formatNumberBytes(1536, true)` → `"1.5 KiB"` |
|
|
363
|
+
| `formatNumberRange` | `(min, max, options?, locale = "en-GB")` | `formatNumberRange(1, 5)` → `"1–5"` |
|
|
364
|
+
| `formatNumberSignDisplay` | `(value, decimalCount = 2, signDisplay = "exceptZero", options?)` | `formatNumberSignDisplay(5)` → `"+5"` |
|
|
212
365
|
|
|
213
366
|
##### String formatters
|
|
214
367
|
|
|
215
|
-
| Function | Signature
|
|
216
|
-
| --------------------- |
|
|
217
|
-
| `formatList` | `(array, options?)` — wraps `Intl.ListFormat`
|
|
218
|
-
| `toStartCase` | `(str)`
|
|
219
|
-
| `toCamelCase` | `(str)`
|
|
220
|
-
| `toPascalCase` | `(str)`
|
|
221
|
-
| `toKebabCase` | `(str)`
|
|
222
|
-
| `toSnakeCase` | `(str)`
|
|
223
|
-
| `truncate` | `(str, maxLength, { ellipsis = "…", wordBoundary = false }?)`
|
|
224
|
-
| `slugify` | `(str)`
|
|
225
|
-
| `pluralize` | `(count, singular, plural?)`
|
|
226
|
-
| `stripDiacritics` | `(str)`
|
|
227
|
-
| `normalizeWhitespace` | `(str)`
|
|
228
|
-
| `maskString` | `(str, { visibleStart = 0, visibleEnd = 4, maskChar = "•" }?)`
|
|
229
|
-
| `formatInitials` | `(name, maxLength = 2)`
|
|
368
|
+
| Function | Signature | Example |
|
|
369
|
+
| --------------------- | -------------------------------------------------------------- | ------------------------------------------------------- |
|
|
370
|
+
| `formatList` | `(array, options?)` — wraps `Intl.ListFormat` | `formatList(["a","b","c"])` → `"a, b, and c"` |
|
|
371
|
+
| `toStartCase` | `(str)` | `toStartCase("hello_world")` → `"Hello World"` |
|
|
372
|
+
| `toCamelCase` | `(str)` | `toCamelCase("hello_world")` → `"helloWorld"` |
|
|
373
|
+
| `toPascalCase` | `(str)` | `toPascalCase("hello_world")` → `"HelloWorld"` |
|
|
374
|
+
| `toKebabCase` | `(str)` | `toKebabCase("helloWorld")` → `"hello-world"` |
|
|
375
|
+
| `toSnakeCase` | `(str)` | `toSnakeCase("helloWorld")` → `"hello_world"` |
|
|
376
|
+
| `truncate` | `(str, maxLength, { ellipsis = "…", wordBoundary = false }?)` | `truncate("Hello world", 8)` → `"Hello w…"` |
|
|
377
|
+
| `slugify` | `(str)` | `slugify("Hello, World!")` → `"hello-world"` |
|
|
378
|
+
| `pluralize` | `(count, singular, plural?)` | `pluralize(2, "child", "children")` → `"children"` |
|
|
379
|
+
| `stripDiacritics` | `(str)` | `stripDiacritics("café")` → `"cafe"` |
|
|
380
|
+
| `normalizeWhitespace` | `(str)` | `normalizeWhitespace(" a\n\tb ")` → `"a b"` |
|
|
381
|
+
| `maskString` | `(str, { visibleStart = 0, visibleEnd = 4, maskChar = "•" }?)` | `maskString("4242424242424242")` → `"••••••••••••4242"` |
|
|
382
|
+
| `formatInitials` | `(name, maxLength = 2)` | `formatInitials("John Smith")` → `"JS"` |
|
|
383
|
+
|
|
384
|
+
#### Type checks
|
|
385
|
+
|
|
386
|
+
Runtime "is this a…?" checks. Each one is a TypeScript type guard, so the
|
|
387
|
+
value's type narrows after the check. Use them on data you don't control:
|
|
388
|
+
API responses, `JSON.parse`, `localStorage`, `catch` errors.
|
|
389
|
+
|
|
390
|
+
```ts
|
|
391
|
+
import { isDefined, isPlainObject, isString } from '@mrmartineau/kit/utils'
|
|
392
|
+
|
|
393
|
+
const ids = [1, null, 2].filter(isDefined) // number[]
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
| Function | `true` for |
|
|
397
|
+
| ----------------- | -------------------------------------------------------------------- |
|
|
398
|
+
| `isString` | strings |
|
|
399
|
+
| `isBoolean` | booleans |
|
|
400
|
+
| `isBigInt` | bigints |
|
|
401
|
+
| `isSymbol` | symbols |
|
|
402
|
+
| `isFunction` | functions, including classes |
|
|
403
|
+
| `isPrimitive` | anything that isn't an object or function, including `null` |
|
|
404
|
+
| `isNumber` | any number, including `NaN` and `Infinity` |
|
|
405
|
+
| `isFiniteNumber` | numbers that aren't `NaN` or `Infinity` |
|
|
406
|
+
| `isInteger` | whole numbers |
|
|
407
|
+
| `isNumericString` | strings that hold a finite number: `'42'` yes, `''` and `'12px'` no |
|
|
408
|
+
| `isNull` | `null` |
|
|
409
|
+
| `isUndefined` | `undefined` |
|
|
410
|
+
| `isNil` | `null` or `undefined` |
|
|
411
|
+
| `isDefined` | anything but `null` or `undefined`; works as a `filter` callback |
|
|
412
|
+
| `isObjectLike` | any non-null object, arrays included |
|
|
413
|
+
| `isObject` | non-null objects that aren't arrays |
|
|
414
|
+
| `isPlainObject` | `{}` literals and `Object.create(null)` only |
|
|
415
|
+
| `hasKey` | objects with that key as their own property: `hasKey(data, 'id')` |
|
|
416
|
+
| `isArray` | arrays |
|
|
417
|
+
| `isArrayOf` | arrays where every item passes a check: `isArrayOf(value, isString)` |
|
|
418
|
+
| `isValidDate` | `Date`s that hold a real date, not `new Date('nonsense')` |
|
|
419
|
+
| `isRegExp` | regular expressions |
|
|
420
|
+
| `isMap` | `Map`s |
|
|
421
|
+
| `isSet` | `Set`s |
|
|
422
|
+
| `isError` | `Error`s and subclasses |
|
|
423
|
+
| `isPromiseLike` | promises and anything else with a `.then` method |
|
|
424
|
+
| `isIterable` | anything `for...of` can loop over, strings included |
|
|
425
|
+
| `isEmpty` | `null`, `undefined`, `''`, `[]`, `{}` and empty `Map`s and `Set`s |
|
|
426
|
+
|
|
427
|
+
More detail and the reasoning behind each one: [Type check helpers](https://zander.wtf/notes/type-check-helpers/).
|
|
230
428
|
|
|
231
429
|
## Exports map
|
|
232
430
|
|
|
233
|
-
| Specifier
|
|
234
|
-
|
|
|
235
|
-
| `@mrmartineau/kit`
|
|
236
|
-
| `@mrmartineau/kit/biome`
|
|
237
|
-
| `@mrmartineau/kit/
|
|
238
|
-
| `@mrmartineau/kit/
|
|
239
|
-
| `@mrmartineau/kit/
|
|
240
|
-
| `@mrmartineau/kit/
|
|
241
|
-
| `@mrmartineau/kit/
|
|
242
|
-
| `@mrmartineau/kit/
|
|
243
|
-
| `@mrmartineau/kit/
|
|
244
|
-
| `@mrmartineau/kit/
|
|
245
|
-
| `@mrmartineau/kit/
|
|
431
|
+
| Specifier | Resolves to |
|
|
432
|
+
| --------------------------------- | -------------------------------- |
|
|
433
|
+
| `@mrmartineau/kit` | `src/index.ts` |
|
|
434
|
+
| `@mrmartineau/kit/biome` | `src/biome/biome.json` |
|
|
435
|
+
| `@mrmartineau/kit/biome/strict` | `src/biome/strict.json` |
|
|
436
|
+
| `@mrmartineau/kit/eslint` | `src/eslint/index.ts` |
|
|
437
|
+
| `@mrmartineau/kit/oxlint` | `src/oxlint/.oxlintrc.json` |
|
|
438
|
+
| `@mrmartineau/kit/oxlint/strict` | `src/oxlint/strict.json` |
|
|
439
|
+
| `@mrmartineau/kit/oxfmt` | `src/oxfmt/.oxfmtrc.json` |
|
|
440
|
+
| `@mrmartineau/kit/prettier` | `src/prettier/.prettierrc.json` |
|
|
441
|
+
| `@mrmartineau/kit/prettier/astro` | `src/prettier/astro.js` |
|
|
442
|
+
| `@mrmartineau/kit/sounds` | `src/sounds/index.ts` (metadata) |
|
|
443
|
+
| `@mrmartineau/kit/sounds/*.mp3` | `src/sounds/*.mp3` (raw files) |
|
|
444
|
+
| `@mrmartineau/kit/utils` | `src/utils/index.ts` |
|
|
445
|
+
| `@mrmartineau/kit/components` | `src/components/index.ts` |
|
|
446
|
+
| `@mrmartineau/kit/hooks` | `src/hooks/index.ts` |
|
|
447
|
+
|
|
448
|
+
## Development
|
|
449
|
+
|
|
450
|
+
This repo dogfoods its own oxlint and oxfmt configs — the root `.oxlintrc.json`
|
|
451
|
+
and `oxfmt.config.ts` use the shared configs in `src/`, so a change to them shows
|
|
452
|
+
up here first.
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
bun run lint # check
|
|
456
|
+
bun run lint:fix # check and apply fixes
|
|
457
|
+
bun run format # format with oxfmt
|
|
458
|
+
bun test
|
|
459
|
+
bun run typecheck
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
CI runs `oxlint --deny-warnings` and `oxfmt --check` alongside typecheck and tests on every pull request.
|
|
246
463
|
|
|
247
464
|
## Attribution
|
|
248
465
|
|
package/package.json
CHANGED
|
@@ -1,49 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrmartineau/kit",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/mrmartineau/kit.git"
|
|
7
7
|
},
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
8
12
|
"exports": {
|
|
9
13
|
".": "./src/index.ts",
|
|
10
14
|
"./biome": "./src/biome/biome.json",
|
|
15
|
+
"./biome/strict": "./src/biome/strict.json",
|
|
11
16
|
"./components": "./src/components/index.ts",
|
|
12
17
|
"./eslint": "./src/eslint/index.ts",
|
|
13
18
|
"./hooks": "./src/hooks/index.ts",
|
|
14
19
|
"./oxfmt": "./src/oxfmt/.oxfmtrc.json",
|
|
15
20
|
"./oxlint": "./src/oxlint/.oxlintrc.json",
|
|
21
|
+
"./oxlint/strict": "./src/oxlint/strict.json",
|
|
16
22
|
"./prettier": "./src/prettier/.prettierrc.json",
|
|
23
|
+
"./prettier/astro": "./src/prettier/astro.js",
|
|
17
24
|
"./sounds": "./src/sounds/index.ts",
|
|
18
25
|
"./sounds/*": "./src/sounds/*",
|
|
19
26
|
"./utils": "./src/utils/index.ts"
|
|
20
27
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "bun test",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "oxlint",
|
|
35
|
+
"lint:fix": "oxlint --fix",
|
|
36
|
+
"format": "oxfmt",
|
|
37
|
+
"ci:lint": "oxlint --deny-warnings && oxfmt --check",
|
|
38
|
+
"release": "semantic-release"
|
|
39
|
+
},
|
|
24
40
|
"devDependencies": {
|
|
25
|
-
"@semantic-release/changelog": "^
|
|
41
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
26
42
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
27
|
-
"@semantic-release/git": "^
|
|
28
|
-
"@semantic-release/github": "^12.0.
|
|
43
|
+
"@semantic-release/git": "^11.0.1",
|
|
44
|
+
"@semantic-release/github": "^12.0.9",
|
|
29
45
|
"@semantic-release/npm": "^13.1.5",
|
|
30
46
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
31
47
|
"@types/bun": "1.3.14",
|
|
32
48
|
"@types/eslint": "^9.6.1",
|
|
33
|
-
"
|
|
49
|
+
"oxfmt": "^0.79.0",
|
|
50
|
+
"oxlint": "^1.94.0",
|
|
51
|
+
"prettier": "^3.9.6",
|
|
52
|
+
"prettier-plugin-astro": "^0.14.1",
|
|
53
|
+
"semantic-release": "^25.0.9"
|
|
34
54
|
},
|
|
35
55
|
"peerDependencies": {
|
|
36
|
-
"eslint": "",
|
|
56
|
+
"eslint": "*",
|
|
57
|
+
"prettier": "^3.0.0",
|
|
58
|
+
"prettier-plugin-astro": "^0.14.0",
|
|
37
59
|
"typescript": "^6.0.3"
|
|
38
60
|
},
|
|
39
61
|
"peerDependenciesMeta": {
|
|
40
62
|
"eslint": {
|
|
41
63
|
"optional": true
|
|
64
|
+
},
|
|
65
|
+
"prettier": {
|
|
66
|
+
"optional": true
|
|
67
|
+
},
|
|
68
|
+
"prettier-plugin-astro": {
|
|
69
|
+
"optional": true
|
|
42
70
|
}
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"test": "bun test",
|
|
46
|
-
"typecheck": "tsc --noEmit",
|
|
47
|
-
"release": "semantic-release"
|
|
48
71
|
}
|
|
49
72
|
}
|
package/src/biome/biome.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/2.
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.5.7/schema.json",
|
|
3
|
+
"root": false,
|
|
3
4
|
"assist": {
|
|
4
5
|
"actions": {
|
|
5
6
|
"source": {
|
|
6
|
-
"organizeImports": "on"
|
|
7
|
-
"useSortedKeys": "on"
|
|
7
|
+
"organizeImports": "on"
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
10
|
"enabled": true
|
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
"formatter": {
|
|
13
13
|
"enabled": true,
|
|
14
14
|
"formatWithErrors": true,
|
|
15
|
-
"indentStyle": "space"
|
|
15
|
+
"indentStyle": "space",
|
|
16
|
+
"indentWidth": 2,
|
|
17
|
+
"lineWidth": 100
|
|
16
18
|
},
|
|
17
19
|
"javascript": {
|
|
18
20
|
"formatter": {
|
|
19
21
|
"quoteStyle": "single",
|
|
20
|
-
"semicolons": "asNeeded"
|
|
22
|
+
"semicolons": "asNeeded",
|
|
23
|
+
"trailingCommas": "all"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"linter": {
|
|
@@ -26,12 +29,39 @@
|
|
|
26
29
|
},
|
|
27
30
|
"enabled": true,
|
|
28
31
|
"rules": {
|
|
29
|
-
"
|
|
32
|
+
"preset": "recommended"
|
|
30
33
|
}
|
|
31
34
|
},
|
|
32
35
|
"vcs": {
|
|
33
36
|
"clientKind": "git",
|
|
34
37
|
"enabled": true,
|
|
35
38
|
"useIgnoreFile": true
|
|
36
|
-
}
|
|
39
|
+
},
|
|
40
|
+
"overrides": [
|
|
41
|
+
{
|
|
42
|
+
"includes": ["**/*.astro", "**/*.svelte", "**/*.vue"],
|
|
43
|
+
"linter": {
|
|
44
|
+
"rules": {
|
|
45
|
+
"correctness": {
|
|
46
|
+
"noUnusedImports": "off",
|
|
47
|
+
"noUnusedVariables": "off"
|
|
48
|
+
},
|
|
49
|
+
"style": {
|
|
50
|
+
"useConst": "off",
|
|
51
|
+
"useImportType": "off"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"includes": ["**/release.config.*"],
|
|
58
|
+
"linter": {
|
|
59
|
+
"rules": {
|
|
60
|
+
"suspicious": {
|
|
61
|
+
"noTemplateCurlyInString": "off"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
37
67
|
}
|