@oviirup/utils 0.0.1-canary.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.
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { slash, truncate } from "../src/string";
3
+
4
+ describe("truncate", () => {
5
+ it("should return the original string if its length is less than or equal to the specified length", () => {
6
+ const text = "Short text";
7
+ const length = 20;
8
+ expect(truncate(text, length)).toBe(text);
9
+ });
10
+
11
+ it('should truncate the string and add "..." if its length exceeds the specified length', () => {
12
+ const text = "This is a very long text that needs truncation";
13
+ const length = 20;
14
+ expect(truncate(text, length)).toBe("This is a very lo...");
15
+ });
16
+
17
+ it("should handle strings with exact length equal to the specified length", () => {
18
+ const text = "Exact length text";
19
+ const length = text.length;
20
+ expect(truncate(text, length)).toBe(text);
21
+ });
22
+
23
+ it("should handle empty strings", () => {
24
+ expect(truncate("", 10)).toBe("");
25
+ });
26
+
27
+ it("should handle negative length by using the ellipsis length", () => {
28
+ const text = "Negative length example";
29
+ const length = -5;
30
+ expect(truncate(text, length)).toBe("...");
31
+ });
32
+ });
33
+
34
+ describe("slash", () => {
35
+ it.each([
36
+ { input: "\\123", expected: "/123" },
37
+ { input: "\\\\", expected: "//" },
38
+ { input: "\\h\\i", expected: "/h/i" },
39
+ { input: "C:\\Users\\John", expected: "C:/Users/John" },
40
+ ])("should convert $input to $expected", ({ input, expected }) => {
41
+ expect(slash(input)).toEqual(expected);
42
+ });
43
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "Node",
7
+ "resolveJsonModule": true,
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "noEmit": true
12
+ },
13
+ "include": ["src/**/*.ts", "tests/**/*.ts"],
14
+ "exclude": ["node_modules", "dist"]
15
+ }