@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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export interface TruncateOptions {
|
|
2
2
|
/** The ellipsis suffix appended when truncation occurs. Default `"…"`. */
|
|
3
|
-
ellipsis?: string
|
|
3
|
+
ellipsis?: string
|
|
4
4
|
/** If `true`, truncates on the last word boundary inside the limit. */
|
|
5
|
-
wordBoundary?: boolean
|
|
5
|
+
wordBoundary?: boolean
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -10,20 +10,16 @@ export interface TruncateOptions {
|
|
|
10
10
|
* The returned string (including ellipsis) will not exceed `maxLength`.
|
|
11
11
|
* @example truncate("Hello world", 8) // "Hello w…"
|
|
12
12
|
*/
|
|
13
|
-
export function truncate(
|
|
14
|
-
|
|
15
|
-
maxLength
|
|
16
|
-
|
|
17
|
-
): string {
|
|
18
|
-
const { ellipsis = "…", wordBoundary = false } = options;
|
|
19
|
-
if (!str || str.length <= maxLength) return str;
|
|
20
|
-
if (maxLength <= ellipsis.length) return ellipsis.slice(0, maxLength);
|
|
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)
|
|
21
17
|
|
|
22
|
-
const sliceLength = maxLength - ellipsis.length
|
|
23
|
-
let truncated = str.slice(0, sliceLength)
|
|
18
|
+
const sliceLength = maxLength - ellipsis.length
|
|
19
|
+
let truncated = str.slice(0, sliceLength)
|
|
24
20
|
if (wordBoundary) {
|
|
25
|
-
const lastSpace = truncated.lastIndexOf(
|
|
26
|
-
if (lastSpace > 0) truncated = truncated.slice(0, lastSpace)
|
|
21
|
+
const lastSpace = truncated.lastIndexOf(' ')
|
|
22
|
+
if (lastSpace > 0) truncated = truncated.slice(0, lastSpace)
|
|
27
23
|
}
|
|
28
|
-
return truncated + ellipsis
|
|
24
|
+
return truncated + ellipsis
|
|
29
25
|
}
|
package/src/utils/index.ts
CHANGED