Add risk forms
Signed-off-by: Bryan Frimin <bryan@getprobo.com> Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
committed by
Sacha Al Himdani
parent
3d4ecf5f8f
commit
fc45d2f00d
@@ -1 +1,2 @@
|
||||
export { objectKeys } from "./object";
|
||||
export { sprintf } from "./string";
|
||||
|
||||
10
packages/helpers/src/string.test.ts
Normal file
10
packages/helpers/src/string.test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { sprintf } from "./string";
|
||||
|
||||
describe("strings", () => {
|
||||
it("should format a string", () => {
|
||||
expect(sprintf("Hello %s", "world")).toBe("Hello world");
|
||||
expect(sprintf("Hello %s %s", "John", "Doe")).toBe("Hello John Doe");
|
||||
expect(sprintf("%2s %1s", "world", "Hello")).toBe("Hello world");
|
||||
});
|
||||
});
|
||||
9
packages/helpers/src/string.ts
Normal file
9
packages/helpers/src/string.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function sprintf(str: string, ...params: unknown[]): string {
|
||||
let i = 0;
|
||||
return str.replace(/%(\d+)?s/g, (_, ...args) => {
|
||||
if (args[0]) {
|
||||
return params[parseInt(args[0]) - 1] as string;
|
||||
}
|
||||
return params[i++] as string;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user