pmtiles_path can have {name} multiple times [#97]

This commit is contained in:
Brandon Liu
2022-11-22 10:47:31 +08:00
parent d986c418e4
commit 9a3f519207
3 changed files with 9 additions and 2 deletions

View File

@@ -40,7 +40,7 @@ const CACHE = new ResolvedValueCache(undefined, undefined, nativeDecompress);
// duplicated code below // duplicated code below
export const pmtiles_path = (name: string, setting?: string): string => { export const pmtiles_path = (name: string, setting?: string): string => {
if (setting) { if (setting) {
return setting.replace("{name}", name); return setting.replaceAll("{name}", name);
} }
return name + ".pmtiles"; return name + ".pmtiles";
}; };

View File

@@ -16,6 +16,13 @@ test("pmtiles path with slash", (assertion) => {
assertion.equal(result, "folder/foo/bar/file.pmtiles"); assertion.equal(result, "folder/foo/bar/file.pmtiles");
}); });
test("pmtiles path with multiple names", (assertion) => {
let result = pmtiles_path("slug","folder/{name}/{name}.pmtiles");
assertion.equal(result, "folder/slug/slug.pmtiles");
result = pmtiles_path("foo/bar","folder/{name}/{name}.pmtiles");
assertion.equal(result, "folder/foo/bar/foo/bar.pmtiles");
});
test("parse tile default", (assertion) => { test("parse tile default", (assertion) => {
let {ok, name, tile, ext} = tile_path("abcd"); let {ok, name, tile, ext} = tile_path("abcd");
assertion.equal(ok, false); assertion.equal(ok, false);

View File

@@ -29,7 +29,7 @@ class KeyNotFoundError extends Error {
export const pmtiles_path = (name: string, setting?: string): string => { export const pmtiles_path = (name: string, setting?: string): string => {
if (setting) { if (setting) {
return setting.replace("{name}", name); return setting.replaceAll("{name}", name);
} }
return name + ".pmtiles"; return name + ".pmtiles";
}; };