@mrmartineau/kit 0.1.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.
Files changed (54) hide show
  1. package/README.md +325 -40
  2. package/package.json +46 -17
  3. package/src/biome/biome.json +37 -7
  4. package/src/biome/strict.json +108 -0
  5. package/src/eslint/index.ts +49 -13
  6. package/src/index.ts +2 -1
  7. package/src/oxfmt/.oxfmtrc.json +5 -1
  8. package/src/oxlint/.oxlintrc.json +12 -3
  9. package/src/oxlint/strict.json +61 -0
  10. package/src/prettier/astro.js +31 -0
  11. package/src/prettier/astro.test.ts +48 -0
  12. package/src/sounds/index.ts +156 -156
  13. package/src/utils/checks/checks.test.ts +162 -0
  14. package/src/utils/checks/collections.ts +63 -0
  15. package/src/utils/checks/index.ts +17 -0
  16. package/src/utils/checks/isEmpty.ts +15 -0
  17. package/src/utils/checks/nullish.ts +26 -0
  18. package/src/utils/checks/numbers.ts +31 -0
  19. package/src/utils/checks/objects.ts +38 -0
  20. package/src/utils/checks/primitives.ts +41 -0
  21. package/src/utils/formatters/constants.ts +1 -0
  22. package/src/utils/formatters/index.ts +24 -0
  23. package/src/utils/formatters/numbers/__tests__/formatNumberBase.test.ts +55 -0
  24. package/src/utils/formatters/numbers/__tests__/formatNumberCurrency.test.ts +55 -0
  25. package/src/utils/formatters/numbers/__tests__/formatNumberDecimal.test.ts +63 -0
  26. package/src/utils/formatters/numbers/__tests__/formatNumberDecimalForceDecimalPlaces.test.ts +29 -0
  27. package/src/utils/formatters/numbers/formatNumberAccounting.ts +27 -0
  28. package/src/utils/formatters/numbers/formatNumberBase.ts +21 -0
  29. package/src/utils/formatters/numbers/formatNumberBytes.ts +29 -0
  30. package/src/utils/formatters/numbers/formatNumberCompact.ts +19 -0
  31. package/src/utils/formatters/numbers/formatNumberCurrency.ts +25 -0
  32. package/src/utils/formatters/numbers/formatNumberDecimal.ts +21 -0
  33. package/src/utils/formatters/numbers/formatNumberDecimalForceDecimalPlaces.ts +23 -0
  34. package/src/utils/formatters/numbers/formatNumberOrdinal.ts +22 -0
  35. package/src/utils/formatters/numbers/formatNumberPercent.ts +21 -0
  36. package/src/utils/formatters/numbers/formatNumberRange.ts +22 -0
  37. package/src/utils/formatters/numbers/formatNumberSignDisplay.ts +24 -0
  38. package/src/utils/formatters/strings/formatInitials.ts +17 -0
  39. package/src/utils/formatters/strings/formatList.test.ts +48 -0
  40. package/src/utils/formatters/strings/formatList.ts +10 -0
  41. package/src/utils/formatters/strings/maskString.ts +27 -0
  42. package/src/utils/formatters/strings/normalizeWhitespace.ts +8 -0
  43. package/src/utils/formatters/strings/pluralize.ts +11 -0
  44. package/src/utils/formatters/strings/slugify.ts +12 -0
  45. package/src/utils/formatters/strings/splitWords.ts +12 -0
  46. package/src/utils/formatters/strings/stripDiacritics.ts +7 -0
  47. package/src/utils/formatters/strings/toCamelCase.ts +17 -0
  48. package/src/utils/formatters/strings/toKebabCase.ts +11 -0
  49. package/src/utils/formatters/strings/toPascalCase.ts +14 -0
  50. package/src/utils/formatters/strings/toSnakeCase.ts +11 -0
  51. package/src/utils/formatters/strings/toStartCase.test.ts +40 -0
  52. package/src/utils/formatters/strings/toStartCase.ts +21 -0
  53. package/src/utils/formatters/strings/truncate.ts +25 -0
  54. package/src/utils/index.ts +2 -0
@@ -0,0 +1,27 @@
1
+ export interface MaskStringOptions {
2
+ /** Number of characters to keep visible at the start. Default 0. */
3
+ visibleStart?: number
4
+ /** Number of characters to keep visible at the end. Default 4. */
5
+ visibleEnd?: number
6
+ /** Character used to mask the hidden portion. Default `"•"`. */
7
+ maskChar?: string
8
+ }
9
+
10
+ /**
11
+ * Masks the middle of a string while keeping a configurable number of
12
+ * characters visible at each end. Useful for partially redacting secrets
13
+ * (tokens, card numbers, emails).
14
+ * @example maskString("4242424242424242", { visibleEnd: 4 }) // "••••••••••••4242"
15
+ */
16
+ export function maskString(str: string, options: MaskStringOptions = {}): string {
17
+ const { visibleStart = 0, visibleEnd = 4, maskChar = '•' } = options
18
+ if (!str) return ''
19
+
20
+ const total = str.length
21
+ if (visibleStart + visibleEnd >= total) return str
22
+
23
+ const start = str.slice(0, visibleStart)
24
+ const end = visibleEnd === 0 ? '' : str.slice(-visibleEnd)
25
+ const masked = maskChar.repeat(total - visibleStart - visibleEnd)
26
+ return `${start}${masked}${end}`
27
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Collapses any run of whitespace (including newlines and tabs) into a single
3
+ * space and trims the result.
4
+ * @example normalizeWhitespace(" hello\n\tworld ") // "hello world"
5
+ */
6
+ export function normalizeWhitespace(str: string): string {
7
+ return str.replace(/\s+/g, ' ').trim()
8
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Picks the singular or plural form based on a count.
3
+ * If `plural` is omitted, appends `"s"` to the singular form.
4
+ * @example pluralize(1, "apple") // "apple"
5
+ * @example pluralize(2, "apple") // "apples"
6
+ * @example pluralize(2, "child", "children") // "children"
7
+ */
8
+ export function pluralize(count: number, singular: string, plural?: string): string {
9
+ if (count === 1) return singular
10
+ return plural ?? `${singular}s`
11
+ }
@@ -0,0 +1,12 @@
1
+ import { stripDiacritics } from './stripDiacritics.js'
2
+
3
+ /**
4
+ * Converts a string to a URL-friendly slug.
5
+ * @example slugify("Hello, World!") // "hello-world"
6
+ */
7
+ export function slugify(str: string): string {
8
+ return stripDiacritics(str)
9
+ .toLowerCase()
10
+ .replace(/[^a-z0-9]+/g, '-')
11
+ .replace(/^-+|-+$/g, '')
12
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Splits a string into lowercase-friendly word tokens. Handles camelCase,
3
+ * PascalCase, ACRONYMTransitions, snake_case, kebab-case, and whitespace.
4
+ */
5
+ export function splitWords(str: string): string[] {
6
+ if (!str) return []
7
+ return str
8
+ .replace(/([a-z\d])([A-Z])/g, '$1 $2')
9
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
10
+ .split(/[\s_-]+/)
11
+ .filter(Boolean)
12
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Removes diacritical marks from a string.
3
+ * @example stripDiacritics("café") // "cafe"
4
+ */
5
+ export function stripDiacritics(str: string): string {
6
+ return str.normalize('NFD').replace(/\p{Diacritic}/gu, '')
7
+ }
@@ -0,0 +1,17 @@
1
+ import { splitWords } from './splitWords.js'
2
+
3
+ /**
4
+ * Converts a string to `camelCase`.
5
+ * @example toCamelCase("hello_world") // "helloWorld"
6
+ */
7
+ export function toCamelCase(str: string): string {
8
+ const words = splitWords(str)
9
+ if (words.length === 0) return ''
10
+ return words
11
+ .map((word, index) => {
12
+ const lower = word.toLowerCase()
13
+ if (index === 0) return lower
14
+ return lower.charAt(0).toUpperCase() + lower.slice(1)
15
+ })
16
+ .join('')
17
+ }
@@ -0,0 +1,11 @@
1
+ import { splitWords } from './splitWords.js'
2
+
3
+ /**
4
+ * Converts a string to `kebab-case`.
5
+ * @example toKebabCase("helloWorld") // "hello-world"
6
+ */
7
+ export function toKebabCase(str: string): string {
8
+ return splitWords(str)
9
+ .map((word) => word.toLowerCase())
10
+ .join('-')
11
+ }
@@ -0,0 +1,14 @@
1
+ import { splitWords } from './splitWords.js'
2
+
3
+ /**
4
+ * Converts a string to `PascalCase`.
5
+ * @example toPascalCase("hello_world") // "HelloWorld"
6
+ */
7
+ export function toPascalCase(str: string): string {
8
+ return splitWords(str)
9
+ .map((word) => {
10
+ const lower = word.toLowerCase()
11
+ return lower.charAt(0).toUpperCase() + lower.slice(1)
12
+ })
13
+ .join('')
14
+ }
@@ -0,0 +1,11 @@
1
+ import { splitWords } from './splitWords.js'
2
+
3
+ /**
4
+ * Converts a string to `snake_case`.
5
+ * @example toSnakeCase("helloWorld") // "hello_world"
6
+ */
7
+ export function toSnakeCase(str: string): string {
8
+ return splitWords(str)
9
+ .map((word) => word.toLowerCase())
10
+ .join('_')
11
+ }
@@ -0,0 +1,40 @@
1
+ import { describe, expect, it } from 'bun:test'
2
+ import { toStartCase } from './toStartCase'
3
+
4
+ describe('toStartCase', () => {
5
+ it('converts underscore_case to Start Case', () => {
6
+ expect(toStartCase('hello_world')).toBe('Hello World')
7
+ expect(toStartCase('multiple_word_string')).toBe('Multiple Word String')
8
+ expect(toStartCase('with_numbers_123')).toBe('With Numbers 123')
9
+ })
10
+
11
+ it('converts camelCase to Start Case', () => {
12
+ expect(toStartCase('helloWorld')).toBe('Hello World')
13
+ expect(toStartCase('multipleWordString')).toBe('Multiple Word String')
14
+ expect(toStartCase('withNumbers123')).toBe('With Numbers123')
15
+ })
16
+
17
+ it('handles already capitalized words', () => {
18
+ expect(toStartCase('Hello World')).toBe('Hello World')
19
+ expect(toStartCase('HELLO WORLD')).toBe('HELLO WORLD')
20
+ })
21
+
22
+ it('capitalizes first letter of each word', () => {
23
+ expect(toStartCase('hello world')).toBe('Hello World')
24
+ expect(toStartCase('a small sentence')).toBe('A Small Sentence')
25
+ })
26
+
27
+ it('handles empty string', () => {
28
+ expect(toStartCase('')).toBe('')
29
+ })
30
+
31
+ it('handles single word', () => {
32
+ expect(toStartCase('hello')).toBe('Hello')
33
+ expect(toStartCase('a')).toBe('A')
34
+ })
35
+
36
+ it('handles mixed formats', () => {
37
+ expect(toStartCase('hello_camelCased-string')).toBe('Hello Camel Cased-string')
38
+ expect(toStartCase('mixed_case-with SPACES')).toBe('Mixed Case-with SPACES')
39
+ })
40
+ })
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Converts a string to Start Case format
3
+ * Similar to the functionality in the 'to-start-case' package
4
+ *
5
+ * @param str The input string to convert
6
+ * @returns The converted string in Start Case format
7
+ * @example
8
+ * toStartCase('hello_world') // 'Hello World'
9
+ * toStartCase('helloWorld') // 'Hello World'
10
+ * toStartCase('hello-world') // 'Hello-world'
11
+ *
12
+ * FYI hyphens will be kept so this will not convert kebab-case to Start Case
13
+ */
14
+ export function toStartCase(str: string): string {
15
+ if (!str) return ''
16
+
17
+ return str
18
+ .replace(/_/g, ' ')
19
+ .replace(/([a-z])([A-Z])/g, (_str, $1, $2) => `${$1} ${$2}`)
20
+ .replace(/(\s|^)(\w)/g, (_str, $1, $2) => $1 + $2.toUpperCase())
21
+ }
@@ -0,0 +1,25 @@
1
+ export interface TruncateOptions {
2
+ /** The ellipsis suffix appended when truncation occurs. Default `"…"`. */
3
+ ellipsis?: string
4
+ /** If `true`, truncates on the last word boundary inside the limit. */
5
+ wordBoundary?: boolean
6
+ }
7
+
8
+ /**
9
+ * Truncates a string to a maximum length, appending an ellipsis when shortened.
10
+ * The returned string (including ellipsis) will not exceed `maxLength`.
11
+ * @example truncate("Hello world", 8) // "Hello w…"
12
+ */
13
+ export function truncate(str: string, maxLength: number, options: TruncateOptions = {}): string {
14
+ const { ellipsis = '…', wordBoundary = false } = options
15
+ if (!str || str.length <= maxLength) return str
16
+ if (maxLength <= ellipsis.length) return ellipsis.slice(0, maxLength)
17
+
18
+ const sliceLength = maxLength - ellipsis.length
19
+ let truncated = str.slice(0, sliceLength)
20
+ if (wordBoundary) {
21
+ const lastSpace = truncated.lastIndexOf(' ')
22
+ if (lastSpace > 0) truncated = truncated.slice(0, lastSpace)
23
+ }
24
+ return truncated + ellipsis
25
+ }
@@ -1 +1,3 @@
1
1
  // Utility functions — add exports here
2
+ export * from './checks/index.js'
3
+ export * from './formatters/index.js'