├── .eslintrc.json ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── nodejs-pr.yml │ └── nodejs.yml ├── .gitignore ├── .madrun.js ├── .npmignore ├── ChangeLog ├── LICENSE ├── README.md ├── lib └── mollify.js ├── package-lock.json └── package.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "plugin:n/recommended", 4 | "plugin:putout/recommended" 5 | ], 6 | "plugins": [ 7 | "putout", 8 | "n" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: coderaiser 2 | patreon: coderaiser 3 | open_collective: cloudcmd 4 | ko_fi: coderaiser 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | - **Version** (`npm -v`): 7 | - **Node Version** `node -v`: 8 | - **OS** (`uname -a` on Linux): 9 | - **Browser name/version**: 10 | - **Used Command Line Parameters**: 11 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | - [ ] commit message named according to [Contributing Guide](https://github.com/coderaiser/cloudcmd/blob/master/CONTRIBUTING.md "Contributting Guide") 7 | - [ ] `npm run codestyle` is OK 8 | - [ ] `npm test` is OK 9 | -------------------------------------------------------------------------------- /.github/workflows/nodejs-pr.yml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | on: 3 | - pull_request 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | env: 8 | NAME: mollify 9 | strategy: 10 | matrix: 11 | node-version: 12 | - 16.x 13 | - 18.x 14 | - 20.x 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Use Node.js ${{ matrix.node-version }} 18 | uses: actions/setup-node@v3 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - name: Install 22 | run: npm install 23 | - name: Lint 24 | run: npm run lint 25 | - uses: actions-rs/toolchain@v1 26 | with: 27 | toolchain: stable 28 | - uses: actions/cache@v3 29 | with: 30 | path: | 31 | ~/.cargo/bin/ 32 | ~/.cargo/registry/index/ 33 | ~/.cargo/registry/cache/ 34 | ~/.cargo/git/db/ 35 | target/ 36 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 37 | - name: Typos Install 38 | run: cargo install typos-cli || echo 'already installed' 39 | - name: Typos 40 | run: typos 41 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | env: 9 | NAME: mollify 10 | strategy: 11 | matrix: 12 | node-version: 13 | - 16.x 14 | - 18.x 15 | - 20.x 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Use Node.js ${{ matrix.node-version }} 19 | uses: actions/setup-node@v3 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | - name: Install 23 | run: npm install 24 | - name: Lint 25 | run: npm run fix:lint 26 | - uses: actions-rs/toolchain@v1 27 | with: 28 | toolchain: stable 29 | - uses: actions/cache@v3 30 | with: 31 | path: | 32 | ~/.cargo/bin/ 33 | ~/.cargo/registry/index/ 34 | ~/.cargo/registry/cache/ 35 | ~/.cargo/git/db/ 36 | target/ 37 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 38 | - name: Typos Install 39 | run: cargo install typos-cli || echo 'already installed' 40 | - name: Typos 41 | run: typos --write-changes 42 | - name: Commit fixes 43 | uses: EndBug/add-and-commit@v9 44 | with: 45 | message: "chore: ${{ env.NAME }}: lint using actions ☘️" 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn-error.log 3 | 4 | .idea 5 | *.swp 6 | coverage 7 | -------------------------------------------------------------------------------- /.madrun.js: -------------------------------------------------------------------------------- 1 | import {run} from 'madrun'; 2 | 3 | export default { 4 | 'lint': () => 'putout .', 5 | 'fix:lint': () => run('lint', '--fix'), 6 | }; 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .madrun.js 2 | yarn-error.log 3 | .* 4 | 5 | coverage 6 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2023.07.08, v6.0.0 2 | 3 | feature: 4 | - d7b11a4 mollify: drop support of node < 16 5 | - 89fb93d package: minify v10.2.0 6 | - 7276eaf package: putout v30.1.1 7 | - a68bbb9 package: eslint-plugin-putout v18.0.0 8 | - c450f81 package: eslint-plugin-n v16.0.1 9 | 10 | 2022.07.19, v5.0.1 11 | 12 | fix: 13 | - mollify: rm useless name arg in minify call 14 | 15 | 16 | 2022.07.19, v5.0.0 17 | 18 | feature: 19 | - (package) eslint-plugin-putout v15.8.1 20 | - (package) madrun v9.0.5 21 | - (package) minify v9.1.0 22 | - (package) ponse v7.0.0 23 | - (package) putout v26.24.0 24 | 25 | 26 | 2022.01.25, v4.0.0 27 | 28 | feature: 29 | - (mollify) drop support of node < 14 30 | - (package) ponse v6.0.0 31 | - (package) eslint-plugin-putout v13.7.0 32 | - (package) minify v8.0.3 33 | - (package) eslint v8.7.0 34 | - (package) putout v24.3.0 35 | - (package) madrun v8.10.1 36 | 37 | 38 | 2020.09.23, v3.0.1 39 | 40 | fix: 41 | - (readme) badge 42 | 43 | 44 | 2020.09.23, v3.0.0 45 | 46 | feature: 47 | - (package) minify v6.0.0 48 | - (mollify) drop support of node < 12 49 | - (package) eslint v7.9.0 50 | - (package) ponse v5.1.1 51 | 52 | 53 | 2018.01.25, v2.0.2 54 | 55 | fix: 56 | - (mollify) getValue (#4) 57 | 58 | 59 | 2017.10.09, v2.0.1 60 | 61 | fix: 62 | - (minify) broken (#3) 63 | 64 | feature: 65 | - (package) lint 66 | 67 | 68 | 2017.07.14, v2.0.0 69 | 70 | feature: 71 | - (mollify) es2015-ify 72 | - (package) drop support of node version < 4 73 | - (package) minify v3.0.0 74 | 75 | 76 | 2017.01.18, v1.0.8 77 | 78 | feature: 79 | - (package) ponse v1.6.0 80 | 81 | 82 | 2015.10.26, v1.0.7 83 | 84 | feature: 85 | - (package) minify v2.0.0 86 | 87 | 88 | 2015.06.11, v1.0.6 89 | 90 | feature: 91 | - (package) ponse v1.4.1 92 | 93 | 94 | 2015.06.09, v1.0.5 95 | 96 | feature: 97 | - (package) rm checkup 98 | - (package) ponse v1.3 99 | 100 | 101 | 2014.12.08, v1.0.4 102 | 103 | feature: 104 | - (package) ponse v1.3 105 | 106 | 107 | 2014.12.03, v1.0.3 108 | 109 | feature: 110 | - (package) minify v1.4.0 111 | 112 | 113 | 2014.12.03, v1.0.2 114 | 115 | fix: 116 | - (package) repository 117 | 118 | 119 | 2014.12.03, v1.0.1 120 | 121 | fix: 122 | - (mollify) options do not set up 123 | 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 coderaiser 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mollify [![License][LicenseIMGURL]][LicenseURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![NPM version][NPMIMGURL]][NPMURL] 2 | 3 | [NPMIMGURL]: https://img.shields.io/npm/v/mollify.svg?style=flat 4 | [LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat 5 | [NPM_INFO_IMG]: https://nodei.co/npm/mollify.png?stars 6 | [NPMURL]: http://npmjs.org/package/mollify 7 | [LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License" 8 | [BuildStatusURL]: https://github.com/coderaiser/node-mollify/actions?query=workflow%3A%22Node+CI%22 "Build Status" 9 | [BuildStatusIMGURL]: https://github.com/coderaiser/node-mollify/workflows/Node%20CI/badge.svg 10 | 11 | Middleware for [minify](https://github.com/coderaiser/minify "Minify"). 12 | 13 | ## Install 14 | 15 | ``` 16 | npm i mollify --save 17 | ``` 18 | 19 | ## How to use? 20 | 21 | ```js 22 | import {fileURLToPath} from 'url'; 23 | import {dirname} from 'path'; 24 | import http from 'http'; 25 | import mollify from 'mollify'; 26 | import express from 'express'; 27 | 28 | const __filename = fileURLToPath(import.meta.url); 29 | const __dirname = dirname(__filename); 30 | 31 | const app = express(); 32 | const server = http.createServer(app); 33 | 34 | const port = 1337; 35 | const ip = '0.0.0.0'; 36 | 37 | app.use(mollify({ 38 | dir: __dirname, 39 | is: true, // default 40 | })); 41 | 42 | app.use(express.static(__dirname)); 43 | 44 | server.listen(port, ip); 45 | ``` 46 | 47 | ## License 48 | 49 | MIT 50 | -------------------------------------------------------------------------------- /lib/mollify.js: -------------------------------------------------------------------------------- 1 | import {join} from 'path'; 2 | import {minify} from 'minify'; 3 | import {send} from 'ponse'; 4 | 5 | export default (options) => { 6 | if (!options) 7 | options = {}; 8 | return mollify.bind(null, options); 9 | }; 10 | 11 | function getValue(value) { 12 | const isFunction = typeof value === 'function'; 13 | 14 | if (isFunction) 15 | return value(); 16 | 17 | return value || value === undefined; 18 | } 19 | 20 | function mollify(options, request, response, next) { 21 | const {url} = request; 22 | const isExt = /\.(js|css|html)$/.test(url); 23 | const {dir = './'} = options; 24 | 25 | const name = join(dir, url); 26 | const isMinify = getValue(options.is); 27 | 28 | if (!isExt || !isMinify) 29 | return next(); 30 | 31 | minify(name) 32 | .then((data) => { 33 | send(data, { 34 | request, 35 | response, 36 | name, 37 | gzip: true, 38 | cache: true, 39 | }); 40 | }) 41 | .catch(next); 42 | } 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mollify", 3 | "version": "6.0.0", 4 | "type": "module", 5 | "description": "minify middleware", 6 | "main": "lib/mollify.js", 7 | "dependencies": { 8 | "minify": "^10.2.0", 9 | "ponse": "^7.0.0" 10 | }, 11 | "devDependencies": { 12 | "eslint": "^8.7.0", 13 | "eslint-plugin-n": "^16.0.1", 14 | "eslint-plugin-putout": "^18.0.0", 15 | "madrun": "^9.0.5", 16 | "putout": "^30.1.1" 17 | }, 18 | "scripts": { 19 | "lint": "madrun lint", 20 | "fix:lint": "madrun fix:lint" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/coderaiser/node-mollify" 25 | }, 26 | "keywords": [ 27 | "minify", 28 | "middleware" 29 | ], 30 | "engines": { 31 | "node": ">=16" 32 | }, 33 | "author": "coderaiser (http://coderaiser.github.io/)", 34 | "license": "MIT", 35 | "bugs": { 36 | "url": "https://github.com/coderaiser/node-mollify.js/issues" 37 | } 38 | } 39 | --------------------------------------------------------------------------------