mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
feat: moved some useful tools to common
This commit is contained in:
committed by
Chi Vinh Le
parent
3c64bb0240
commit
c81d612c70
@@ -0,0 +1,11 @@
|
||||
import ensureEndSlash from "./ensureEndSlash";
|
||||
|
||||
it("should add slash to the end", () => {
|
||||
const path = ensureEndSlash("/test");
|
||||
expect(path).toBe("/test/");
|
||||
});
|
||||
|
||||
it("should not add slash to the end if it's already there", () => {
|
||||
const path = ensureEndSlash("/test/");
|
||||
expect(path).toBe("/test/");
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function ensureEndSlash(p: string) {
|
||||
return p.match(/\/$/) ? p : `${p}/`;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import ensureNoEndSlash from "./ensureNoEndSlash";
|
||||
|
||||
it("should remove the slash from the end", () => {
|
||||
const path = ensureNoEndSlash("/test/");
|
||||
expect(path).toBe("/test");
|
||||
});
|
||||
|
||||
it("should not change a string if there is no ending slash", () => {
|
||||
const path = ensureNoEndSlash("/test");
|
||||
expect(path).toBe("/test");
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function ensureEndSlash(p: string) {
|
||||
return p.replace(/\/$/, "");
|
||||
}
|
||||
@@ -3,3 +3,5 @@ export { default as animationFrame } from "./animationFrame";
|
||||
export { default as pascalCase } from "./pascalCase";
|
||||
export { default as oncePerFrame } from "./oncePerFrame";
|
||||
export { default as isBeforeDate } from "./isBeforeDate";
|
||||
export { default as ensureEndSlash } from "./ensureEndSlash";
|
||||
export { default as ensureNoEndSlash } from "./ensureNoEndSlash";
|
||||
|
||||
Reference in New Issue
Block a user