@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
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.5.7/schema.json",
|
|
3
|
+
"root": false,
|
|
4
|
+
"extends": ["./biome.json"],
|
|
5
|
+
"linter": {
|
|
6
|
+
"rules": {
|
|
7
|
+
"complexity": {
|
|
8
|
+
"useMaxParams": {
|
|
9
|
+
"level": "error",
|
|
10
|
+
"options": {
|
|
11
|
+
"max": 3
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"correctness": {
|
|
16
|
+
"noNestedComponentDefinitions": "error",
|
|
17
|
+
"useHookAtTopLevel": "error"
|
|
18
|
+
},
|
|
19
|
+
"performance": {
|
|
20
|
+
"noBarrelFile": "error",
|
|
21
|
+
"noNamespaceImport": "error",
|
|
22
|
+
"noReExportAll": "error"
|
|
23
|
+
},
|
|
24
|
+
"style": {
|
|
25
|
+
"noCommonJs": "error",
|
|
26
|
+
"noDefaultExport": "error",
|
|
27
|
+
"noEnum": "error",
|
|
28
|
+
"noNestedTernary": "error",
|
|
29
|
+
"noNonNullAssertion": "error",
|
|
30
|
+
"useConsistentTypeDefinitions": {
|
|
31
|
+
"level": "error",
|
|
32
|
+
"options": {
|
|
33
|
+
"style": "interface"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"useFilenamingConvention": {
|
|
37
|
+
"level": "error",
|
|
38
|
+
"options": {
|
|
39
|
+
"filenameCases": ["kebab-case"],
|
|
40
|
+
"requireAscii": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"useImportType": "error"
|
|
44
|
+
},
|
|
45
|
+
"suspicious": {
|
|
46
|
+
"noArrayIndexKey": "error",
|
|
47
|
+
"noConsole": {
|
|
48
|
+
"level": "error",
|
|
49
|
+
"options": {
|
|
50
|
+
"allow": ["warn", "error"]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"noDoubleEquals": "error",
|
|
54
|
+
"noEmptyBlockStatements": "error",
|
|
55
|
+
"noExplicitAny": "error",
|
|
56
|
+
"noTsIgnore": "error",
|
|
57
|
+
"useArraySortCompare": "error"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"overrides": [
|
|
62
|
+
{
|
|
63
|
+
"includes": ["**/*.astro", "**/*.svelte", "**/*.vue"],
|
|
64
|
+
"linter": {
|
|
65
|
+
"rules": {
|
|
66
|
+
"correctness": {
|
|
67
|
+
"noUnusedImports": "off",
|
|
68
|
+
"noUnusedVariables": "off"
|
|
69
|
+
},
|
|
70
|
+
"style": {
|
|
71
|
+
"useConst": "off",
|
|
72
|
+
"useImportType": "off"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"includes": ["**/release.config.*"],
|
|
79
|
+
"linter": {
|
|
80
|
+
"rules": {
|
|
81
|
+
"suspicious": {
|
|
82
|
+
"noTemplateCurlyInString": "off"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"includes": ["**/*.config.*", "**/*.d.ts"],
|
|
89
|
+
"linter": {
|
|
90
|
+
"rules": {
|
|
91
|
+
"style": {
|
|
92
|
+
"noDefaultExport": "off"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"includes": ["**/scripts/**"],
|
|
99
|
+
"linter": {
|
|
100
|
+
"rules": {
|
|
101
|
+
"suspicious": {
|
|
102
|
+
"noConsole": "off"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
package/src/eslint/index.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import type { Linter } from 'eslint'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Base rules, layered on top of a recommended set rather than replacing it.
|
|
5
|
+
* This config intentionally has no runtime dependencies, so bring your own
|
|
6
|
+
* base — see the README:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import js from '@eslint/js'
|
|
10
|
+
* import kit from '@mrmartineau/kit/eslint'
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig([js.configs.recommended, ...kit])
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Deliberately excludes formatting rules — use Prettier, Biome or oxfmt for
|
|
16
|
+
* those. `curly` is the one exception: it guards against the class of bug where
|
|
17
|
+
* a statement is accidentally added outside an unbraced block, which no
|
|
18
|
+
* formatter will catch for you.
|
|
19
|
+
*/
|
|
20
|
+
export const base: Linter.Config[] = [
|
|
4
21
|
{
|
|
5
22
|
name: '@mrmartineau/kit/base',
|
|
6
23
|
rules: {
|
|
@@ -12,21 +29,40 @@ const config: Linter.Config[] = [
|
|
|
12
29
|
'object-shorthand': 'error',
|
|
13
30
|
'prefer-template': 'error',
|
|
14
31
|
'prefer-arrow-callback': 'error',
|
|
15
|
-
'no-restricted-imports': [
|
|
16
|
-
'error',
|
|
17
|
-
{
|
|
18
|
-
patterns: [
|
|
19
|
-
{
|
|
20
|
-
group: ['../*'],
|
|
21
|
-
message: 'Prefer absolute imports over relative parent imports.',
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
32
|
eqeqeq: ['error', 'always'],
|
|
27
33
|
curly: ['error', 'multi-line'],
|
|
28
34
|
},
|
|
29
35
|
},
|
|
30
36
|
]
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Opt-in: ban `../` imports in favour of path aliases.
|
|
40
|
+
*
|
|
41
|
+
* Not part of the base config because it only makes sense once a project has
|
|
42
|
+
* aliases configured, and it can't be satisfied at all by colocated tests or
|
|
43
|
+
* sibling-directory imports in a library layout.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import kit, { noRelativeParentImports } from '@mrmartineau/kit/eslint'
|
|
47
|
+
*
|
|
48
|
+
* export default defineConfig([...kit, noRelativeParentImports])
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const noRelativeParentImports: Linter.Config = {
|
|
52
|
+
name: '@mrmartineau/kit/no-relative-parent-imports',
|
|
53
|
+
rules: {
|
|
54
|
+
'no-restricted-imports': [
|
|
55
|
+
'error',
|
|
56
|
+
{
|
|
57
|
+
patterns: [
|
|
58
|
+
{
|
|
59
|
+
group: ['../*'],
|
|
60
|
+
message: 'Prefer absolute imports over relative parent imports.',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default base
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from './utils/index.js'
|
|
1
|
+
export * from './sounds/index.ts'
|
|
2
|
+
export * from './utils/index.js'
|
package/src/oxfmt/.oxfmtrc.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxfmt/configuration_schema.json",
|
|
3
|
+
"astro": true,
|
|
3
4
|
"printWidth": 100,
|
|
4
5
|
"semi": false,
|
|
5
6
|
"singleQuote": true,
|
|
7
|
+
"sortImports": {
|
|
8
|
+
"newlinesBetween": false
|
|
9
|
+
},
|
|
6
10
|
"tabWidth": 2,
|
|
7
11
|
"trailingComma": "all",
|
|
8
12
|
"useTabs": false
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
|
|
3
3
|
"categories": {
|
|
4
4
|
"correctness": "error",
|
|
5
5
|
"perf": "warn",
|
|
@@ -7,12 +7,21 @@
|
|
|
7
7
|
},
|
|
8
8
|
"env": {
|
|
9
9
|
"browser": true,
|
|
10
|
-
"es2024": true
|
|
10
|
+
"es2024": true,
|
|
11
|
+
"node": true
|
|
11
12
|
},
|
|
12
13
|
"plugins": ["typescript", "unicorn", "import", "react", "jsx-a11y"],
|
|
13
14
|
"rules": {
|
|
14
15
|
"no-console": "warn",
|
|
15
16
|
"no-debugger": "error",
|
|
16
|
-
"typescript/
|
|
17
|
+
"typescript/consistent-type-imports": "error",
|
|
18
|
+
"typescript/no-explicit-any": "warn",
|
|
19
|
+
"no-unused-vars": [
|
|
20
|
+
"error",
|
|
21
|
+
{
|
|
22
|
+
"ignoreRestSiblings": true
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"react/react-in-jsx-scope": "off"
|
|
17
26
|
}
|
|
18
27
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json",
|
|
3
|
+
"extends": ["./.oxlintrc.json"],
|
|
4
|
+
"rules": {
|
|
5
|
+
"eqeqeq": "error",
|
|
6
|
+
"max-params": [
|
|
7
|
+
"error",
|
|
8
|
+
{
|
|
9
|
+
"max": 3
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"no-console": [
|
|
13
|
+
"error",
|
|
14
|
+
{
|
|
15
|
+
"allow": ["warn", "error"]
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"no-empty": "error",
|
|
19
|
+
"no-nested-ternary": "error",
|
|
20
|
+
"import/no-commonjs": "error",
|
|
21
|
+
"import/no-default-export": "error",
|
|
22
|
+
"import/no-namespace": "error",
|
|
23
|
+
"oxc/no-barrel-file": [
|
|
24
|
+
"error",
|
|
25
|
+
{
|
|
26
|
+
"threshold": 0
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"react/no-array-index-key": "error",
|
|
30
|
+
"react/no-danger": "error",
|
|
31
|
+
"react/no-unstable-nested-components": "error",
|
|
32
|
+
"react/rules-of-hooks": "error",
|
|
33
|
+
"typescript/ban-ts-comment": "error",
|
|
34
|
+
"typescript/consistent-type-definitions": ["error", "interface"],
|
|
35
|
+
"typescript/no-explicit-any": "error",
|
|
36
|
+
"typescript/no-non-null-assertion": "error",
|
|
37
|
+
"typescript/no-require-imports": "error",
|
|
38
|
+
"unicorn/filename-case": [
|
|
39
|
+
"error",
|
|
40
|
+
{
|
|
41
|
+
"case": "kebabCase"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"unicorn/no-array-reverse": "error",
|
|
45
|
+
"unicorn/no-array-sort": "error"
|
|
46
|
+
},
|
|
47
|
+
"overrides": [
|
|
48
|
+
{
|
|
49
|
+
"files": ["**/*.config.*", "**/*.d.ts"],
|
|
50
|
+
"rules": {
|
|
51
|
+
"import/no-default-export": "off"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"files": ["**/scripts/**"],
|
|
56
|
+
"rules": {
|
|
57
|
+
"no-console": "off"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import baseWithSchema from './.prettierrc.json' with { type: 'json' }
|
|
2
|
+
|
|
3
|
+
// `$schema` is meaningful in the JSON file but Prettier warns about it as an
|
|
4
|
+
// unknown option when a config is loaded as a JS module.
|
|
5
|
+
const { $schema, ...base } = baseWithSchema
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base Prettier config plus `.astro` support.
|
|
9
|
+
*
|
|
10
|
+
* Kept separate from `@mrmartineau/kit/prettier` because Prettier hard-errors
|
|
11
|
+
* when a plugin listed in `plugins` can't be resolved — putting the Astro
|
|
12
|
+
* plugin in the base config would break every non-Astro consumer.
|
|
13
|
+
*
|
|
14
|
+
* Requires `prettier-plugin-astro` to be installed in the consuming project.
|
|
15
|
+
*
|
|
16
|
+
* @type {import('prettier').Config}
|
|
17
|
+
*/
|
|
18
|
+
const config = {
|
|
19
|
+
...base,
|
|
20
|
+
plugins: ['prettier-plugin-astro'],
|
|
21
|
+
overrides: [
|
|
22
|
+
{
|
|
23
|
+
files: '*.astro',
|
|
24
|
+
options: {
|
|
25
|
+
parser: 'astro',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default config
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
import { format } from 'prettier'
|
|
3
|
+
import baseConfig from './.prettierrc.json'
|
|
4
|
+
import astroConfig from './astro.js'
|
|
5
|
+
|
|
6
|
+
const source = `---
|
|
7
|
+
import Layout from "../layouts/Layout.astro";
|
|
8
|
+
const { title = "hi" } = Astro.props;
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<Layout title={title}>
|
|
12
|
+
<h1 class="a" >{ title }</h1>
|
|
13
|
+
</Layout>
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
test('astro config inherits every option from the base config', () => {
|
|
17
|
+
const { $schema, ...base } = baseConfig
|
|
18
|
+
for (const [key, value] of Object.entries(base)) {
|
|
19
|
+
expect(astroConfig[key as keyof typeof astroConfig]).toEqual(value)
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('astro config does not leak $schema as a Prettier option', () => {
|
|
24
|
+
expect(astroConfig).not.toHaveProperty('$schema')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('astro config registers the astro plugin and parser override', () => {
|
|
28
|
+
expect(astroConfig.plugins).toEqual(['prettier-plugin-astro'])
|
|
29
|
+
expect(astroConfig.overrides).toEqual([{ files: '*.astro', options: { parser: 'astro' } }])
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('formats an .astro file using the base style rules', async () => {
|
|
33
|
+
const output = await format(source, {
|
|
34
|
+
...astroConfig,
|
|
35
|
+
filepath: 'Demo.astro',
|
|
36
|
+
parser: 'astro',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
expect(output).toBe(`---
|
|
40
|
+
import Layout from '../layouts/Layout.astro'
|
|
41
|
+
const { title = 'hi' } = Astro.props
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<Layout title={title}>
|
|
45
|
+
<h1 class="a">{title}</h1>
|
|
46
|
+
</Layout>
|
|
47
|
+
`)
|
|
48
|
+
})
|