more misc

This commit is contained in:
fyears 2021-11-28 12:18:44 +08:00
parent 0d75ea92b1
commit 2eb1545f9d
2 changed files with 13 additions and 3 deletions

View File

@ -46,8 +46,8 @@ export const getFolderLevels = (x: string) => {
let i = 0; let i = 0;
for (let index = 0; index + 1 < y1.length; index++) { for (let index = 0; index + 1 < y1.length; index++) {
const k = y1.slice(0, index + 1).join("/"); const k = y1.slice(0, index + 1).join("/");
if (k !== '' && k!== '/') { if (k !== "" && k !== "/") {
res.push(k) res.push(k);
} }
} }
return res; return res;
@ -145,3 +145,13 @@ export const getPathFolder = (a: string) => {
const b = path.posix.dirname(a); const b = path.posix.dirname(a);
return b.endsWith("/") ? b : `${b}/`; return b.endsWith("/") ? b : `${b}/`;
}; };
/**
* https://stackoverflow.com/questions/54511144
* @param a
* @param delimiter
* @returns
*/
export const setToString = (a: Set<string>, delimiter: string = ",") => {
return [...a].join(delimiter);
};

View File

@ -70,7 +70,7 @@ describe("Misc: get folder levels", () => {
expect(misc.getFolderLevels(item3)).to.deep.equal(res3); expect(misc.getFolderLevels(item3)).to.deep.equal(res3);
}); });
it("should treat path starting with / correctly", ()=> { it("should treat path starting with / correctly", () => {
const item = "/xxx/yyy/zzz.md"; const item = "/xxx/yyy/zzz.md";
const res = ["/xxx", "/xxx/yyy"]; const res = ["/xxx", "/xxx/yyy"];
expect(misc.getFolderLevels(item)).to.deep.equal(res); expect(misc.getFolderLevels(item)).to.deep.equal(res);