From 4a2446c6abf7bb9136f9bedd2320a951e7edfe86 Mon Sep 17 00:00:00 2001 From: artiebits Date: Thu, 7 Jan 2021 11:25:54 +0100 Subject: [PATCH] Apply Prettier --- examples/electron-react/.eslintrc.js | 6 ++---- examples/electron-react/README.md | 1 - examples/electron-react/src/main/index.js | 4 ++-- examples/electron-react/src/renderer/index.js | 14 ++++---------- examples/express-server/README.md | 5 +++-- examples/express-server/src/list.js | 5 +---- examples/express-server/src/print.js | 8 +++----- src/electron-util.js | 2 +- src/electron-util.test.js | 6 +++--- src/index.js | 4 ++-- src/index.test.js | 2 +- src/unix/get-default-printer.js | 2 +- src/unix/get-printers.js | 4 ++-- src/unix/get-printers.test.js | 2 +- src/unix/print.js | 2 +- src/unix/print.test.js | 4 ++-- src/win32/get-default-printer.js | 4 ++-- src/win32/get-printers.js | 2 +- src/win32/get-printers.test.js | 2 +- webpack.production.config.js | 10 +++++----- 20 files changed, 38 insertions(+), 51 deletions(-) diff --git a/examples/electron-react/.eslintrc.js b/examples/electron-react/.eslintrc.js index 5b2fecb..caaa9fb 100644 --- a/examples/electron-react/.eslintrc.js +++ b/examples/electron-react/.eslintrc.js @@ -1,10 +1,8 @@ module.exports = { - extends: [ - "plugin:react/recommended" - ], + extends: ["plugin:react/recommended"], settings: { react: { version: "latest", }, }, -}; \ No newline at end of file +}; diff --git a/examples/electron-react/README.md b/examples/electron-react/README.md index 32134c5..487f3c0 100644 --- a/examples/electron-react/README.md +++ b/examples/electron-react/README.md @@ -10,7 +10,6 @@ yarn yarn dev ``` - ### Scripts ```bash diff --git a/examples/electron-react/src/main/index.js b/examples/electron-react/src/main/index.js index ad6722b..5eddcab 100644 --- a/examples/electron-react/src/main/index.js +++ b/examples/electron-react/src/main/index.js @@ -11,7 +11,7 @@ let mainWindow; function createMainWindow() { const window = new BrowserWindow({ - webPreferences: { nodeIntegration: true } + webPreferences: { nodeIntegration: true }, }); if (isDevelopment) { @@ -25,7 +25,7 @@ function createMainWindow() { formatUrl({ pathname: path.join(__dirname, "index.html"), protocol: "file", - slashes: true + slashes: true, }) ); } diff --git a/examples/electron-react/src/renderer/index.js b/examples/electron-react/src/renderer/index.js index a86db30..4284d4c 100644 --- a/examples/electron-react/src/renderer/index.js +++ b/examples/electron-react/src/renderer/index.js @@ -10,17 +10,14 @@ function App() { const [selectedPrinter, selectPrinter] = useState(null); useEffect(() => { - printer - .getPrinters() - .then(setPrinters) - .catch(console.error); + printer.getPrinters().then(setPrinters).catch(console.error); }, []); - const onPrinterChangeHandler = event => { + const onPrinterChangeHandler = (event) => { selectPrinter(event.target.value); }; - const onSubmitHandler = event => { + const onSubmitHandler = (event) => { event.preventDefault(); const options = {}; @@ -28,10 +25,7 @@ function App() { options.printer = selectedPrinter; } - printer - .print(pdfUrl, options) - .then(console.log) - .catch(console.error); + printer.print(pdfUrl, options).then(console.log).catch(console.error); }; const renderPrinter = (printer, index) => { diff --git a/examples/express-server/README.md b/examples/express-server/README.md index ee791e5..d568d70 100644 --- a/examples/express-server/README.md +++ b/examples/express-server/README.md @@ -11,5 +11,6 @@ npm run start ``` It will start a server on http://localhost:8080. -* Open [/list](http://localhost:8080/list) to retrieve a list of printers. -* Open [/print](http://localhost:8080/print?url=https://easypost-files.s3-us-west-2.amazonaws.com/files/postage_label/20190716/15ad63c69e654e228d92a1ee0aa9d536.pdf) to print a PDF file. + +- Open [/list](http://localhost:8080/list) to retrieve a list of printers. +- Open [/print](http://localhost:8080/print?url=https://easypost-files.s3-us-west-2.amazonaws.com/files/postage_label/20190716/15ad63c69e654e228d92a1ee0aa9d536.pdf) to print a PDF file. diff --git a/examples/express-server/src/list.js b/examples/express-server/src/list.js index 7605b94..7ec127d 100644 --- a/examples/express-server/src/list.js +++ b/examples/express-server/src/list.js @@ -9,10 +9,7 @@ function list(request, response) { response.send({ status: "error", error }); } - printer - .getPrinters() - .then(onSuccess) - .catch(onError); + printer.getPrinters().then(onSuccess).catch(onError); } module.exports = list; diff --git a/examples/express-server/src/print.js b/examples/express-server/src/print.js index af36d86..ebee4cd 100644 --- a/examples/express-server/src/print.js +++ b/examples/express-server/src/print.js @@ -13,8 +13,8 @@ function print(request, response) { } fetch(request.query.url) - .then(res => res.buffer()) - .then(buffer => { + .then((res) => res.buffer()) + .then((buffer) => { const pdf = save(buffer); printer @@ -36,9 +36,7 @@ function remove(pdf) { } function randomString() { - return Math.random() - .toString(36) - .substring(7); + return Math.random().toString(36).substring(7); } module.exports = print; diff --git a/src/electron-util.js b/src/electron-util.js index 37254ac..5be782d 100644 --- a/src/electron-util.js +++ b/src/electron-util.js @@ -9,6 +9,6 @@ const isUsingAsar = process.mainModule && process.mainModule.filename.includes("app.asar"); -export const fixPathForAsarUnpack = path => { +export const fixPathForAsarUnpack = (path) => { return isUsingAsar ? path.replace("app.asar", "app.asar.unpacked") : path; }; diff --git a/src/electron-util.test.js b/src/electron-util.test.js index bf9b60e..db822b0 100644 --- a/src/electron-util.test.js +++ b/src/electron-util.test.js @@ -15,11 +15,11 @@ test("fixes path for Electron apps", () => { global.process = { ...originalProcess, versions: { - electron: "0.0.0" + electron: "0.0.0", }, mainModule: { - filename: "/app.asar/index.html" - } + filename: "/app.asar/index.html", + }, }; expect(require("./electron-util").fixPathForAsarUnpack(path)).toBe( diff --git a/src/index.js b/src/index.js index e56a2ca..b99e32c 100644 --- a/src/index.js +++ b/src/index.js @@ -12,14 +12,14 @@ switch (os.platform()) { module.exports = { print: require("./unix/print"), getPrinters: require("./unix/get-printers"), - getDefaultPrinter: require("./unix/get-default-printer") + getDefaultPrinter: require("./unix/get-default-printer"), }; break; case "win32": module.exports = { print: require("./win32/print"), getPrinters: require("./win32/get-printers"), - getDefaultPrinter: require("./win32/get-default-printer") + getDefaultPrinter: require("./win32/get-default-printer"), }; break; default: diff --git a/src/index.test.js b/src/index.test.js index 277559a..bb9cd8d 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -5,7 +5,7 @@ jest.mock("os"); describe.each([ ["Linux", "linux"], ["Darwin", "darwin"], - ["Windows", "win32"] + ["Windows", "win32"], ])("%i operating system", (_, alias) => { test("has `print`, `getDefaultPrinter` and `getPrinters` methods", () => { jest.resetModules(); diff --git a/src/unix/get-default-printer.js b/src/unix/get-default-printer.js index 8d25987..6e24344 100644 --- a/src/unix/get-default-printer.js +++ b/src/unix/get-default-printer.js @@ -3,7 +3,7 @@ const execAsync = require("../execAsync"); const getDefaultPrinter = () => { - const parseResult = output => output.substr(output.indexOf(":") + 1).trim(); + const parseResult = (output) => output.substr(output.indexOf(":") + 1).trim(); return execAsync("lpstat", ["-d"], parseResult); }; diff --git a/src/unix/get-printers.js b/src/unix/get-printers.js index 05683f6..651ed04 100644 --- a/src/unix/get-printers.js +++ b/src/unix/get-printers.js @@ -3,11 +3,11 @@ const execAsync = require("../execAsync"); const getPrinters = () => { - const parseResult = output => { + const parseResult = (output) => { return output .trim() .split("\n") - .map(e => e.substr(0, e.indexOf(" "))); + .map((e) => e.substr(0, e.indexOf(" "))); }; return execAsync("lpstat", ["-a"], parseResult); }; diff --git a/src/unix/get-printers.test.js b/src/unix/get-printers.test.js index 1a2d9e9..5109f27 100644 --- a/src/unix/get-printers.test.js +++ b/src/unix/get-printers.test.js @@ -26,7 +26,7 @@ test("returns list of available printers", () => { ); return expect(getPrinters()).resolves.toStrictEqual([ "macOS_Printer", - "Zebra" + "Zebra", ]); }); diff --git a/src/unix/print.js b/src/unix/print.js index d33f359..2147610 100644 --- a/src/unix/print.js +++ b/src/unix/print.js @@ -18,7 +18,7 @@ const print = (pdf, options = {}) => { if (unix) { if (!Array.isArray(unix)) throw "options.unix should be an array"; - unix.map(unixArg => args.push(...unixArg.split(" "))); + unix.map((unixArg) => args.push(...unixArg.split(" "))); } return execAsync("lp", args); diff --git a/src/unix/print.test.js b/src/unix/print.test.js index fceb2ab..681767b 100644 --- a/src/unix/print.test.js +++ b/src/unix/print.test.js @@ -47,7 +47,7 @@ test("sends PDF file to the specific printer", () => { const filename = "assets/pdf-sample.pdf"; const printer = "Zebra"; const options = { - printer + printer, }; return print(filename, options).then(() => { expect(execAsync).toHaveBeenCalledWith("lp", [filename, "-d", printer]); @@ -64,7 +64,7 @@ test("allows users to pass OS specific options", () => { "-d", printer, "-o", - "sides=one-sided" + "sides=one-sided", ]); }); }); diff --git a/src/win32/get-default-printer.js b/src/win32/get-default-printer.js index aeb6fd6..50fbcec 100644 --- a/src/win32/get-default-printer.js +++ b/src/win32/get-default-printer.js @@ -3,14 +3,14 @@ const execAsync = require("../execAsync"); const getDefaultPrinter = () => { - const stdoutHandler = stdout => { + const stdoutHandler = (stdout) => { const printers = stdout .trim() .split(/\s*[\r\n]+/) // We remove the first element from the result because // wmic printer get name will show a list of printers under "Name" title. .slice(1); - const defaultPrinter = printers.filter(e => e.indexOf("TRUE") === 0); + const defaultPrinter = printers.filter((e) => e.indexOf("TRUE") === 0); if (defaultPrinter.length === 0) { return ""; } diff --git a/src/win32/get-printers.js b/src/win32/get-printers.js index cdbf812..eacb606 100644 --- a/src/win32/get-printers.js +++ b/src/win32/get-printers.js @@ -3,7 +3,7 @@ const execAsync = require("../execAsync"); const getPrinters = () => { - const stdoutHandler = stdout => + const stdoutHandler = (stdout) => stdout .trim() .split(/\s*[\r\n]+/) diff --git a/src/win32/get-printers.test.js b/src/win32/get-printers.test.js index 64934a4..68d71c9 100644 --- a/src/win32/get-printers.test.js +++ b/src/win32/get-printers.test.js @@ -34,7 +34,7 @@ test("returns list of available printers", () => { // Windows will write to stdout a list of printers under "Name" title. return expect(getPrinters()).resolves.toStrictEqual([ "Windows Printer", - "Zebra" + "Zebra", ]); }); diff --git a/webpack.production.config.js b/webpack.production.config.js index bb02439..8748fb6 100644 --- a/webpack.production.config.js +++ b/webpack.production.config.js @@ -8,17 +8,17 @@ module.exports = { output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js", - libraryTarget: "umd" + libraryTarget: "umd", }, plugins: [ new CleanWebpackPlugin(), new CopyPlugin([ { from: "./src/win32/SumatraPDF.exe" }, - { from: "./src/types.d.ts" } - ]) + { from: "./src/types.d.ts" }, + ]), ], target: "node", node: { - __dirname: false - } + __dirname: false, + }, };