@esmate/utils 1.2.4 → 1.3.1
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 +14 -15
- package/dist/string.d.ts +5 -2
- package/dist/string.js +1 -1
- package/package.json +3 -3
- package/dist/toolkit.d.ts +0 -1
- package/dist/toolkit.js +0 -1
package/README.md
CHANGED
|
@@ -23,21 +23,12 @@ npm install @esmate/utils
|
|
|
23
23
|
|
|
24
24
|
### ESToolkit Utilities
|
|
25
25
|
|
|
26
|
-
Access [es-toolkit](https://es-toolkit.dev/reference/array/at.html) functions through the main package export
|
|
27
|
-
dedicated toolkit subpath.
|
|
28
|
-
|
|
29
|
-
**Import from main package:**
|
|
26
|
+
Access [es-toolkit](https://es-toolkit.dev/reference/array/at.html) functions through the main package export.
|
|
30
27
|
|
|
31
28
|
```ts
|
|
32
29
|
import { delay, invariant } from "@esmate/utils";
|
|
33
30
|
```
|
|
34
31
|
|
|
35
|
-
**Import from toolkit subpath:**
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { delay, invariant } from "@esmate/utils/toolkit";
|
|
39
|
-
```
|
|
40
|
-
|
|
41
32
|
📚 **Documentation**: [es-toolkit reference](https://es-toolkit.dev/reference/array/at.html)
|
|
42
33
|
|
|
43
34
|
---
|
|
@@ -69,6 +60,14 @@ import { round, sqrt } from "@esmate/utils/math";
|
|
|
69
60
|
|
|
70
61
|
### String Utilities
|
|
71
62
|
|
|
63
|
+
Access **string** utilities for common string operations.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { fixTypos, titleize } from "@esmate/utils";
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
📚 **Documentation**: [View source](https://github.com/VienDinhCom/esmate/blob/main/packages/utils/src/string.ts)
|
|
70
|
+
|
|
72
71
|
#### `titleize()`
|
|
73
72
|
|
|
74
73
|
Converts strings to proper title case using the [title](https://www.npmjs.com/package/title) package.
|
|
@@ -76,10 +75,12 @@ Converts strings to proper title case using the [title](https://www.npmjs.com/pa
|
|
|
76
75
|
```ts
|
|
77
76
|
import { titleize } from "@esmate/utils/string";
|
|
78
77
|
|
|
79
|
-
const
|
|
80
|
-
```
|
|
78
|
+
const title = titleize("hello world"); // "Hello World"
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
const chicagoTitle = titleize("love of my life", { style: "chicago" }); // "Love of My Life"
|
|
81
|
+
|
|
82
|
+
const specialTitle = titleize("i love ESMate", { special: ["ESMate"] }); // "I Love ESMate"
|
|
83
|
+
```
|
|
83
84
|
|
|
84
85
|
#### `fixTypos()`
|
|
85
86
|
|
|
@@ -90,5 +91,3 @@ import { fixTypos } from "@esmate/utils/string";
|
|
|
90
91
|
|
|
91
92
|
const result = fixTypos("This is a text with typos..."); // "This is a text with typos…"
|
|
92
93
|
```
|
|
93
|
-
|
|
94
|
-
📚 **Documentation**: [View source](https://github.com/VienDinhCom/esmate/blob/main/packages/utils/src/string.ts)
|
package/dist/string.d.ts
CHANGED
|
@@ -3,16 +3,19 @@ import type { Configuration, Locale } from "typopo";
|
|
|
3
3
|
* Formats a string to be used as a title.
|
|
4
4
|
* @param str The string to format.
|
|
5
5
|
* @param options The options to use.
|
|
6
|
+
* @param options.style The style of the title.
|
|
7
|
+
* @param options.special A list of special words to keep as-is.
|
|
6
8
|
* @returns The formatted string.
|
|
7
9
|
*/
|
|
8
10
|
export declare function titleize(str: string, options?: {
|
|
9
|
-
|
|
11
|
+
style?: "chicago";
|
|
10
12
|
special?: string[];
|
|
11
13
|
}): string;
|
|
12
14
|
/**
|
|
13
15
|
* Fixes typos in a string using typopo.
|
|
14
16
|
* @param str The string to fix.
|
|
15
|
-
* @param options The options to use.
|
|
17
|
+
* @param options The options to use, including `typopo` configuration.
|
|
18
|
+
* @param options.locale The locale to use (e.g., "en-us", "ru").
|
|
16
19
|
* @returns The fixed string.
|
|
17
20
|
*/
|
|
18
21
|
export declare function fixTypos(str: string, options?: Configuration & {
|
package/dist/string.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_title__ from "title";
|
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE_typopo__ from "typopo";
|
|
4
4
|
function titleize(str, options) {
|
|
5
5
|
str = str.replace(/\s+/g, " ");
|
|
6
|
-
if (options?.
|
|
6
|
+
if (options?.style === "chicago") return (0, __WEBPACK_EXTERNAL_MODULE_title__["default"])(str, options);
|
|
7
7
|
const specialWordsLower = options?.special?.map((s)=>s.toLocaleLowerCase());
|
|
8
8
|
return str.split(" ").map((word)=>specialWordsLower?.includes(word.toLocaleLowerCase()) ? word : (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_string_d01e99ad__.capitalize)(word)).join(" ");
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@esmate/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"description": "JavaScript/TypeScript utils, functions, and classes in one package.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
|
-
"types": "./dist/toolkit.d.ts",
|
|
23
|
-
"import": "./dist/toolkit.js"
|
|
22
|
+
"types": "./dist/pkgs/es-toolkit.d.ts",
|
|
23
|
+
"import": "./dist/pkgs/es-toolkit.js"
|
|
24
24
|
},
|
|
25
25
|
"./*": {
|
|
26
26
|
"types": "./dist/*.d.ts",
|
package/dist/toolkit.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "es-toolkit";
|
package/dist/toolkit.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "es-toolkit";
|