Skip to content

Commit 74f2b89

Browse files
committed
Update version to 4.8.0, add new formatters (formatCount, formatDateRange, formatPascalCase), and enhance formatCamelCase and formatPercentage functions. Document changes in CHANGELOG.md and README.md.
1 parent f4e6bf2 commit 74f2b89

12 files changed

Lines changed: 151 additions & 19 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# deverything
22

3+
## 4.8.0
4+
5+
### Minor Changes
6+
7+
- formatters
8+
39
## 4.7.1
410

511
### Patch Changes

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@ Contributions always welcome!
147147

148148
### Formatters
149149

150-
- `formatCamelCase()`
150+
- `formatCamelCase()` "hello-world" => "helloWorld"
151151
- `formatCookies()` { cookie1: "1", cookie2: "2" } => "cookie1=1; cookie2=2"
152+
- `formatCount()` "#items: 3, #users: 5"
153+
- `formatDateRange()` "2026-02-09T00:00... ⮕ 2026-02-10T00:00..."
154+
- `formatIndexProgress()` => "[2/10]"
152155
- `formatNumber()` 1000 => "1,000" or "1K" or 0.112 => "11.2%"
156+
- `formatPascalCase()` "hello-world" => "HelloWorld"
153157
- `formatPercentage()` 0.11 => "11%"
154-
- `formatIndexProgress()` => "[2/10]"
155158
- `stringToCSSUnicode()` "hello" => "\000068\000065\00006c\00006c\00006f" use this for CSS
156159
- `stringToUnicode()` "hello" => "\u0068\u0065\u006c\u006c\u006f"
157160

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deverything",
3-
"version": "4.7.1",
3+
"version": "4.8.0",
44
"description": "Everything you need for Dev",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, expect, test } from "vitest";
2+
import { formatCamelCase } from "./formatCamelCase";
3+
4+
describe("formatCamelCase", () => {
5+
test("should convert hyphenated string to camelCase", () => {
6+
expect(formatCamelCase("hello-world")).toBe("helloWorld");
7+
});
8+
9+
test("should convert underscore string to camelCase", () => {
10+
expect(formatCamelCase("hello_world")).toBe("helloWorld");
11+
});
12+
13+
test("should convert space-separated string to camelCase", () => {
14+
expect(formatCamelCase("hello world")).toBe("helloWorld");
15+
});
16+
17+
test("should handle multiple words", () => {
18+
expect(formatCamelCase("hello-world-foo-bar")).toBe("helloWorldFooBar");
19+
});
20+
21+
test("should handle mixed separators", () => {
22+
expect(formatCamelCase("hello-world_foo bar")).toBe("helloWorldFooBar");
23+
});
24+
25+
test("should handle single word", () => {
26+
expect(formatCamelCase("hello")).toBe("hello");
27+
});
28+
29+
test("should handle already capitalized string", () => {
30+
expect(formatCamelCase("Hello World")).toBe("helloWorld");
31+
});
32+
33+
test("should handle numbers in the string", () => {
34+
expect(formatCamelCase("hello-world-123")).toBe("helloWorld123");
35+
});
36+
});

src/formatters/formatCamelCase.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import { formatPascalCase } from "./formatPascalCase";
2+
3+
/**
4+
* @example formatCamelCase("hello-world") => "helloWorld"
5+
* @example formatCamelCase("hello_world") => "helloWorld"
6+
* @example formatCamelCase("Hello World") => "helloWorld"
7+
*/
18
export const formatCamelCase = (str: string) => {
2-
return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, (_m, p1, p2) => {
3-
return p1.toUpperCase() + p2;
4-
});
9+
const newString = formatPascalCase(str);
10+
return newString.charAt(0).toLowerCase() + newString.slice(1);
511
};

src/formatters/formatCount.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @example formatCount({items: [1, 2, 3]}) => "#items: 3"
3+
* @example formatCount({items: [1, 2, 3], things: 5}) => "#items: 3, #things: 5"
4+
* @example formatCount({users: 10, posts: 20}) => "#users: 10, #posts: 20"
5+
*/
6+
export const formatCount = (
7+
counters: Record<string, any[] | number>
8+
): string => {
9+
return Object.entries(counters)
10+
.map(([key, value]) => {
11+
const count = Array.isArray(value) ? value.length : value;
12+
return `#${key}: ${count}`;
13+
})
14+
.join(", ");
15+
};

src/formatters/formatDateRange.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { parseDate } from "../helpers/parseDate";
2+
import { Datey } from "../types";
3+
4+
/**
5+
* @example formatDateRange(startDate, endDate) => "2026-02-09T00:00:00.000Z ⮕ 2026-02-10T00:00:00.000Z"
6+
*/
7+
export const formatDateRange = (startDate: Datey, endDate: Datey): string => {
8+
return `${parseDate(startDate)?.toISOString()}${parseDate(endDate)?.toISOString()}`;
9+
};

src/formatters/formatLatin.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, expect, test } from "vitest";
2+
import { formatPascalCase } from "./formatPascalCase";
3+
4+
describe("formatPascalCase", () => {
5+
test("should convert hyphenated string to PascalCase", () => {
6+
expect(formatPascalCase("hello-world")).toBe("HelloWorld");
7+
});
8+
9+
test("should convert underscore string to PascalCase", () => {
10+
expect(formatPascalCase("hello_world")).toBe("HelloWorld");
11+
});
12+
13+
test("should convert space-separated string to PascalCase", () => {
14+
expect(formatPascalCase("hello world")).toBe("HelloWorld");
15+
});
16+
17+
test("should handle multiple words", () => {
18+
expect(formatPascalCase("hello-world-foo-bar")).toBe("HelloWorldFooBar");
19+
});
20+
21+
test("should handle mixed separators", () => {
22+
expect(formatPascalCase("hello-world_foo bar")).toBe("HelloWorldFooBar");
23+
});
24+
25+
test("should handle single word", () => {
26+
expect(formatPascalCase("hello")).toBe("Hello");
27+
});
28+
29+
test("should handle already capitalized string", () => {
30+
expect(formatPascalCase("HELLO-WORLD")).toBe("HelloWorld");
31+
});
32+
33+
test("should handle numbers in the string", () => {
34+
expect(formatPascalCase("hello-world-123")).toBe("HelloWorld123");
35+
});
36+
});

src/formatters/formatPascalCase.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @example formatPascalCase("hello-world") => "HelloWorld"
3+
* @example formatPascalCase("hello_world") => "HelloWorld"
4+
* @example formatPascalCase("hello world") => "HelloWorld"
5+
*/
6+
export const formatPascalCase = (str: string) => {
7+
return str
8+
.toLowerCase()
9+
.replace(/[-_\s]+(.)/g, (_match, char) => char.toUpperCase())
10+
.replace(/^(.)/, (char) => char.toUpperCase());
11+
};

0 commit comments

Comments
 (0)