Skip to content

Commit b02a626

Browse files
committed
feat: add max to parseNumber
1 parent 91fe287 commit b02a626

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

__tests__/convert.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ test("should convert to secure", () => {
5757
test("keep number", () => {
5858
expect(starkString("48g39 d").parseNumber().toString()).toBe("4839");
5959
});
60+
61+
test("parseNumber with max", () => {
62+
expect(starkString("48g39 d").parseNumber({ max: 100 }).toString()).toBe(
63+
"100",
64+
);
65+
});

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class StarkString extends NativeString {
7373

7474
/**
7575
* Used for decode Persian Characters in URL
76-
* https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-Functions.js
76+
* https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-Functions.
77+
* s
7778
*/
7879
fixURL(): StarkString {
7980
this._value = decodeURL(this._value);
@@ -82,7 +83,8 @@ class StarkString extends NativeString {
8283

8384
/**
8485
* Used for decode Persian Characters in URL
85-
* https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-Functions.js
86+
* https://fa.wikipedia.org/wiki/مدیاویکی:Gadget-Extra-Editbuttons-Functions.
87+
* s
8688
*/
8789
decodeURL(): StarkString {
8890
this._value = decodeURL(this._value);
@@ -124,8 +126,13 @@ class StarkString extends NativeString {
124126
}
125127

126128
/** Remove anything expect numbers */
127-
parseNumber(): StarkString {
129+
parseNumber({ max }: { max?: number } = {}): StarkString {
128130
this._value = parseNumber(this._value);
131+
if (typeof max === "number") {
132+
if (Number(this._value) > max) {
133+
this._value = String(max);
134+
}
135+
}
129136
return this;
130137
}
131138

@@ -145,4 +152,4 @@ class StarkString extends NativeString {
145152
//CommonJS module is defined
146153
export default starkString;
147154

148-
export type {StarkString}
155+
export type { StarkString };

0 commit comments

Comments
 (0)