diff --git a/src/getLicense.spec.ts b/src/getLicense.spec.ts index 296d4dc..1df4f61 100644 --- a/src/getLicense.spec.ts +++ b/src/getLicense.spec.ts @@ -1,4 +1,5 @@ import MIT from "@ovyerus/licenses/licenses/MIT.json"; +import Apache20 from "@ovyerus/licenses/licenses/Apache-2.0.json"; import getLicense from "./getLicense"; @@ -12,6 +13,14 @@ test("replaces the author and year fields in the MIT license", () => { ); }); +test("replaces the author and year fields in the Apache-2.0 license", () => { + expect(getLicense("Apache-2.0", { author: "Ovyerus", yyyy: "2020" })).toEqual( + Apache20.licenseText + .replace(//g, "Ovyerus") + .replace(/\[(yyyy)\]/g, "2020") + ); +}); + test("throws on invalid license", () => { expect(() => getLicense("bad identifier")).toThrowError( new TypeError("license is not a valid SPDX identifier") diff --git a/src/getLicense.ts b/src/getLicense.ts index dc1adb0..2a67c2a 100644 --- a/src/getLicense.ts +++ b/src/getLicense.ts @@ -26,7 +26,10 @@ export function getLicense( // Remove any undefined or falsey values ([, value]) => value )) - modified = modified.replace(new RegExp(`<${key}>`, "g"), value); + modified = modified + .replace(new RegExp(`<${key}>`, "g"), value) + // Some licenses, like Apache 2.0 use square bracket templating for some values. + .replace(new RegExp(`\\[${key}\\]`, "g"), value); return modified; }