diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ba311..0ed0188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ The URL structure has changed to make it possible to add more options. The old U Some examples: -- `/scaled/500x500/foobar.jpg` -> `/scaled/width:500|height:500/foobar.jpg` -- `/scaled/x400/foobar.jpg.webp` -> `/scaled/height:400|convert:webp/foobar.jpg.webp` +- `/scaled/500x500/foobar.jpg` -> `/scaled/width:500_height:500/foobar.jpg` +- `/scaled/x400/foobar.jpg.webp` -> `/scaled/height:400_convert:webp/foobar.jpg.webp` # Upgrade to V3 diff --git a/README.md b/README.md index 9f7b9c6..261f0de 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Subsequent requests to the bucket will therefore skip the Lambda function entire The function will allow resizing of images, by width, height, or both dimensions. Example paths: -- `/scaled/width:500|height:500/foobar.jpg`: this would generate a 500x500 version of the image `foobar.jpg`. +- `/scaled/width:500_height:500/foobar.jpg`: this would generate a 500x500 version of the image `foobar.jpg`. - `/scaled/width:500/foobar.jpg`: omitting the `height` would generate a 500px wide version of the image. - `/scaled/height:500/foobar.jpg`: omitting the `width` would generate a 500px high version of the image. @@ -50,7 +50,7 @@ The function will allow resizing of images, by width, height, or both dimensions You can convert an image to a different format. -- `/scaled/width:500|height:500|convert:webp/foobar.jpg.webp`: this will create a **webp** version of the file `foobar.jpg`, scaled to 500x500. +- `/scaled/width:500_height:500_convert:webp/foobar.jpg.webp`: this will create a **webp** version of the file `foobar.jpg`, scaled to 500x500. ## Versions @@ -102,7 +102,7 @@ This package includes a local image server, allowing you to test with this image yarn serve ``` -Then use http://localhost:8888/scaled/width:500|height:500/foo/bar.jpg for your image requests. +Then use http://localhost:8888/scaled/width:500_height:500/foo/bar.jpg for your image requests. Currently, you will get back a random image with the requested dimensions. diff --git a/test/parseOptions.test.js b/test/parseOptions.test.js index 3cf7400..821a38b 100644 --- a/test/parseOptions.test.js +++ b/test/parseOptions.test.js @@ -2,7 +2,7 @@ const parseOptions = require("../util/parseOptions.js"); it("should parse the options", function () { expect(parseOptions("width:100")).toEqual({ width: "100" }); - expect(parseOptions("width:100|height:200")).toEqual({ + expect(parseOptions("width:100_height:200")).toEqual({ width: "100", height: "200", }); diff --git a/test/pathToParams.test.js b/test/pathToParams.test.js index c9e1feb..e48587c 100644 --- a/test/pathToParams.test.js +++ b/test/pathToParams.test.js @@ -5,7 +5,7 @@ const pathToParams = require("../util/pathToParams.js"); describe("pathToParams", () => { describe("Given a URL with both dimensions and no output-format", () => { it("Will extract dimensions and use the original extension as outputFormat", () => { - const input = "scaled/width:500|height:320/foo.jpg"; + const input = "scaled/width:500_height:320/foo.jpg"; const [options, path] = pathToParams(input); expect(options.width).toBe("500"); expect(options.height).toBe("320"); @@ -32,7 +32,7 @@ describe("pathToParams", () => { }); describe("Given a URL with a longer directory path", () => { it("Will extract the correct path", () => { - const input = "/scaled/width:500|height:500/my/deeper/folder/foo.jpg"; + const input = "/scaled/width:500_height:500/my/deeper/folder/foo.jpg"; const [options, path] = pathToParams(input, ["jpg"]); expect(options.width).toBe("500"); expect(options.height).toBe("500"); @@ -41,7 +41,7 @@ describe("pathToParams", () => { }); describe("Given a file with a double extension", () => { it("Will treat the first extension as part of the original filename, and the last part as the outputFormat", () => { - const input = "/scaled/width:300|height:120|convert:png/foo.jpg.png"; + const input = "/scaled/width:300_height:120_convert:png/foo.jpg.png"; const [options, path] = pathToParams(input); const inputFormat = getInputFormat(path, options.convert); const outputFormat = getOutputFormat(path, options.convert); @@ -52,7 +52,7 @@ describe("pathToParams", () => { expect(inputFormat).toBe("jpg"); }); it("Will be able to handle repeating extensions.", () => { - const input = "/scaled/width:300|height:120/foo.jpg.jpg"; + const input = "/scaled/width:300_height:120/foo.jpg.jpg"; const [options, path] = pathToParams(input); expect(options.width).toBe("300"); expect(options.height).toBe("120"); diff --git a/util/parseOptions.js b/util/parseOptions.js index 66aa61b..b8f794b 100644 --- a/util/parseOptions.js +++ b/util/parseOptions.js @@ -7,7 +7,7 @@ module.exports = (optionsString) => { let options = {}; - optionsString.split("|").forEach((option) => { + optionsString.split("_").forEach((option) => { const [action, ...params] = option.split(":"); // Currently only one parameter is supported. options[action] = params[0];