feat: moved some useful tools to common

This commit is contained in:
Wyatt Johnson
2018-11-01 18:15:42 +01:00
committed by Chi Vinh Le
parent 3c64bb0240
commit c81d612c70
9 changed files with 13 additions and 12 deletions
@@ -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/");
});
+3
View File
@@ -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(/\/$/, "");
}
+2
View File
@@ -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";