├── .eslintignore ├── .eslintrc.yml ├── .github └── workflows │ ├── ci.yml │ └── scorecard.yml ├── .gitignore ├── HISTORY.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test ├── .eslintrc.yml ├── browserify.js └── methods.js /.eslintignore: -------------------------------------------------------------------------------- 1 | coverage 2 | node_modules 3 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | root: true 2 | extends: standard 3 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | - pull_request 5 | - push 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-20.04 10 | strategy: 11 | matrix: 12 | name: 13 | - Node.js 0.6 14 | - Node.js 0.8 15 | - Node.js 0.10 16 | - Node.js 0.12 17 | - io.js 1.x 18 | - io.js 2.x 19 | - io.js 3.x 20 | - Node.js 4.x 21 | - Node.js 5.x 22 | - Node.js 6.x 23 | - Node.js 7.x 24 | - Node.js 8.x 25 | - Node.js 9.x 26 | - Node.js 10.x 27 | - Node.js 11.x 28 | - Node.js 12.x 29 | - Node.js 13.x 30 | - Node.js 14.x 31 | - Node.js 15.x 32 | - Node.js 16.x 33 | - Node.js 17.x 34 | - Node.js 18.x 35 | - Node.js 19.x 36 | - Node.js 20.x 37 | - Node.js 21.x 38 | 39 | include: 40 | - name: Node.js 0.6 41 | node-version: "0.6" 42 | npm-i: mocha@1.21.5 43 | npm-rm: nyc 44 | 45 | - name: Node.js 0.8 46 | node-version: "0.8" 47 | npm-i: mocha@2.5.3 48 | npm-rm: nyc 49 | 50 | - name: Node.js 0.10 51 | node-version: "0.10" 52 | npm-i: mocha@3.5.3 nyc@10.3.2 53 | 54 | - name: Node.js 0.12 55 | node-version: "0.12" 56 | npm-i: mocha@3.5.3 nyc@10.3.2 57 | 58 | - name: io.js 1.x 59 | node-version: "1.8" 60 | npm-i: mocha@3.5.3 nyc@10.3.2 61 | 62 | - name: io.js 2.x 63 | node-version: "2.5" 64 | npm-i: mocha@3.5.3 nyc@10.3.2 65 | 66 | - name: io.js 3.x 67 | node-version: "3.3" 68 | npm-i: mocha@3.5.3 nyc@10.3.2 69 | 70 | - name: Node.js 4.x 71 | node-version: "4.9" 72 | npm-i: mocha@5.2.0 nyc@11.9.0 73 | 74 | - name: Node.js 5.x 75 | node-version: "5.12" 76 | npm-i: mocha@5.2.0 nyc@11.9.0 77 | 78 | - name: Node.js 6.x 79 | node-version: "6.17" 80 | npm-i: mocha@6.2.2 nyc@14.1.1 81 | 82 | - name: Node.js 7.x 83 | node-version: "7.10" 84 | npm-i: mocha@6.2.2 nyc@14.1.1 85 | 86 | - name: Node.js 8.x 87 | node-version: "8.17" 88 | npm-i: mocha@7.1.2 nyc@14.1.1 89 | 90 | - name: Node.js 9.x 91 | node-version: "9.11" 92 | npm-i: mocha@7.1.2 nyc@14.1.1 93 | 94 | - name: Node.js 10.x 95 | node-version: "10.24" 96 | npm-i: mocha@8.4.0 97 | 98 | - name: Node.js 11.x 99 | node-version: "11.15" 100 | npm-i: mocha@8.4.0 101 | 102 | - name: Node.js 12.x 103 | node-version: "12.22" 104 | npm-i: mocha@9.2.2 105 | 106 | - name: Node.js 13.x 107 | node-version: "13.14" 108 | npm-i: mocha@9.2.2 109 | 110 | - name: Node.js 14.x 111 | node-version: "14.21" 112 | 113 | - name: Node.js 15.x 114 | node-version: "15.14" 115 | 116 | - name: Node.js 16.x 117 | node-version: "16.20" 118 | 119 | - name: Node.js 17.x 120 | node-version: "17.9" 121 | 122 | - name: Node.js 18.x 123 | node-version: "18.18" 124 | 125 | - name: Node.js 19.x 126 | node-version: "19.9" 127 | 128 | - name: Node.js 20.x 129 | node-version: "20.9" 130 | 131 | - name: Node.js 21.x 132 | node-version: "21.1" 133 | 134 | steps: 135 | - uses: actions/checkout@v3 136 | 137 | - name: Install Node.js ${{ matrix.node-version }} 138 | shell: bash -eo pipefail -l {0} 139 | run: | 140 | if [[ "${{ matrix.node-version }}" == 0.6* ]]; then 141 | sudo sh -c 'echo "deb http://us.archive.ubuntu.com/ubuntu/ bionic universe" >> /etc/apt/sources.list' 142 | sudo sh -c 'echo "deb http://security.ubuntu.com/ubuntu bionic-security main" >> /etc/apt/sources.list' 143 | sudo apt-get update 144 | sudo apt-get install g++-4.8 gcc-4.8 libssl1.0-dev python2 python-is-python2 145 | export CC=/usr/bin/gcc-4.8 146 | export CXX=/usr/bin/g++-4.8 147 | fi 148 | nvm install --default ${{ matrix.node-version }} 149 | if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then 150 | nvm install --alias=npm 0.10 151 | nvm use ${{ matrix.node-version }} 152 | if [[ "$(npm -v)" == 1.1.* ]]; then 153 | nvm exec npm npm install -g npm@1.1 154 | ln -fs "$(which npm)" "$(dirname "$(nvm which npm)")/npm" 155 | else 156 | sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" 157 | fi 158 | npm config set strict-ssl false 159 | fi 160 | dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" 161 | 162 | - name: Configure npm 163 | run: | 164 | if [[ "$(npm config get package-lock)" == "true" ]]; then 165 | npm config set package-lock false 166 | else 167 | npm config set shrinkwrap false 168 | fi 169 | 170 | - name: Remove npm module(s) ${{ matrix.npm-rm }} 171 | run: npm rm --silent --save-dev ${{ matrix.npm-rm }} 172 | if: matrix.npm-rm != '' 173 | 174 | - name: Install npm module(s) ${{ matrix.npm-i }} 175 | run: npm install --save-dev ${{ matrix.npm-i }} 176 | if: matrix.npm-i != '' 177 | 178 | - name: Setup Node.js version-specific dependencies 179 | shell: bash 180 | run: | 181 | # eslint for linting 182 | # - remove on Node.js < 12 183 | if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then 184 | node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ 185 | grep -E '^eslint(-|$)' | \ 186 | sort -r | \ 187 | xargs -n1 npm rm --silent --save-dev 188 | fi 189 | 190 | - name: Install Node.js dependencies 191 | run: npm install 192 | 193 | - name: Install browserify 194 | run: | 195 | if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -ge 1 ]]; then 196 | npm install --save-dev browserify@16 197 | fi 198 | 199 | - name: List environment 200 | id: list_env 201 | shell: bash 202 | run: | 203 | echo "node@$(node -v)" 204 | echo "npm@$(npm -v)" 205 | npm -s ls ||: 206 | (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT" 207 | 208 | - name: Run tests 209 | shell: bash 210 | run: | 211 | if npm -ps ls nyc | grep -q nyc; then 212 | npm run test-ci 213 | else 214 | npm test 215 | fi 216 | 217 | - name: Lint code 218 | if: steps.list_env.outputs.eslint != '' 219 | run: npm run lint 220 | 221 | - name: Collect code coverage 222 | uses: coverallsapp/github-action@master 223 | if: steps.list_env.outputs.nyc != '' 224 | with: 225 | github-token: ${{ secrets.GITHUB_TOKEN }} 226 | flag-name: run-${{ matrix.test_number }} 227 | parallel: true 228 | 229 | coverage: 230 | needs: test 231 | runs-on: ubuntu-latest 232 | steps: 233 | - name: Upload code coverage 234 | uses: coverallsapp/github-action@master 235 | with: 236 | github-token: ${{ secrets.github_token }} 237 | parallel-finished: true 238 | -------------------------------------------------------------------------------- /.github/workflows/scorecard.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are provided 2 | # by a third-party and are governed by separate terms of service, privacy 3 | # policy, and support documentation. 4 | 5 | name: Scorecard supply-chain security 6 | on: 7 | # For Branch-Protection check. Only the default branch is supported. See 8 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 9 | branch_protection_rule: 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: '16 21 * * 1' 14 | push: 15 | branches: [ "master" ] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | analysis: 22 | name: Scorecard analysis 23 | runs-on: ubuntu-latest 24 | permissions: 25 | # Needed to upload the results to code-scanning dashboard. 26 | security-events: write 27 | # Needed to publish results and get a badge (see publish_results below). 28 | id-token: write 29 | # Uncomment the permissions below if installing in a private repository. 30 | # contents: read 31 | # actions: read 32 | 33 | steps: 34 | - name: "Checkout code" 35 | uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 36 | with: 37 | persist-credentials: false 38 | 39 | - name: "Run analysis" 40 | uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6 41 | with: 42 | results_file: results.sarif 43 | results_format: sarif 44 | # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: 45 | # - you want to enable the Branch-Protection check on a *public* repository, or 46 | # - you are installing Scorecard on a *private* repository 47 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. 48 | # repo_token: ${{ secrets.SCORECARD_TOKEN }} 49 | 50 | # Public repositories: 51 | # - Publish results to OpenSSF REST API for easy access by consumers 52 | # - Allows the repository to include the Scorecard badge. 53 | # - See https://github.com/ossf/scorecard-action#publishing-results. 54 | # For private repositories: 55 | # - `publish_results` will always be set to `false`, regardless 56 | # of the value entered here. 57 | publish_results: true 58 | 59 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 60 | # format to the repository Actions tab. 61 | - name: "Upload artifact" 62 | uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 63 | with: 64 | name: SARIF file 65 | path: results.sarif 66 | retention-days: 5 67 | 68 | # Upload the results to GitHub's code scanning dashboard. 69 | - name: "Upload to code-scanning" 70 | uses: github/codeql-action/upload-sarif@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 71 | with: 72 | sarif_file: results.sarif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store* 3 | *.log 4 | *.gz 5 | 6 | node_modules 7 | coverage 8 | cache 9 | 10 | package-lock.json 11 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | 1.1.2 / 2016-01-17 2 | ================== 3 | 4 | * perf: enable strict mode 5 | 6 | 1.1.1 / 2014-12-30 7 | ================== 8 | 9 | * Improve `browserify` support 10 | 11 | 1.1.0 / 2014-07-05 12 | ================== 13 | 14 | * Add `CONNECT` method 15 | 16 | 1.0.1 / 2014-06-02 17 | ================== 18 | 19 | * Fix module to work with harmony transform 20 | 21 | 1.0.0 / 2014-05-08 22 | ================== 23 | 24 | * Add `PURGE` method 25 | 26 | 0.1.0 / 2013-10-28 27 | ================== 28 | 29 | * Add `http.METHODS` support 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2013-2014 TJ Holowaychuk 4 | Copyright (c) 2015-2016 Douglas Christopher Wilson 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | 'Software'), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Methods 2 | 3 | [![NPM Version][npm-version-image]][npm-url] 4 | [![NPM Downloads][npm-downloads-image]][npm-url] 5 | [![Node.js Version][node-image]][node-url] 6 | [![Build Status][ci-image]][ci-url] 7 | [![Coverage Status][coveralls-image]][coveralls-url] 8 | 9 | HTTP verbs that Node.js core's HTTP parser supports. 10 | 11 | This module provides an export that is just like `http.METHODS` from Node.js core, 12 | with the following differences: 13 | 14 | * All method names are lower-cased. 15 | * Contains a fallback list of methods for Node.js versions that do not have a 16 | `http.METHODS` export (0.10 and lower). 17 | * Provides the fallback list when using tools like `browserify` without pulling 18 | in the `http` shim module. 19 | 20 | ## Install 21 | 22 | This is a [Node.js](https://nodejs.org/en/) module available through the 23 | [npm registry](https://www.npmjs.com/). Installation is done using the 24 | [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): 25 | 26 | ```sh 27 | $ npm install methods 28 | ``` 29 | 30 | ## API 31 | 32 | ```js 33 | var methods = require('methods') 34 | ``` 35 | 36 | ### methods 37 | 38 | This is an array of lower-cased method names that Node.js supports. If Node.js 39 | provides the `http.METHODS` export, then this is the same array lower-cased, 40 | otherwise it is a snapshot of the verbs from Node.js 0.10. 41 | 42 | ## License 43 | 44 | [MIT](LICENSE) 45 | 46 | [ci-image]: https://badgen.net/github/checks/jshttp/methods/master?label=ci 47 | [ci-url]: https://github.com/jshttp/methods/actions/workflows/ci.yml 48 | [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/methods/master 49 | [coveralls-url]: https://coveralls.io/r/jshttp/methods?branch=master 50 | [node-image]: https://badgen.net/npm/node/methods 51 | [node-url]: https://nodejs.org/en/download 52 | [npm-downloads-image]: https://badgen.net/npm/dm/methods 53 | [npm-url]: https://npmjs.org/package/methods 54 | [npm-version-image]: https://badgen.net/npm/v/methods 55 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * methods 3 | * Copyright(c) 2013-2014 TJ Holowaychuk 4 | * Copyright(c) 2015-2016 Douglas Christopher Wilson 5 | * MIT Licensed 6 | */ 7 | 8 | 'use strict' 9 | 10 | /** 11 | * Module dependencies. 12 | * @private 13 | */ 14 | 15 | var http = require('http') 16 | 17 | /** 18 | * Module exports. 19 | * @public 20 | */ 21 | 22 | module.exports = getCurrentNodeMethods() || getBasicNodeMethods() 23 | 24 | /** 25 | * Get the current Node.js methods. 26 | * @private 27 | */ 28 | 29 | function getCurrentNodeMethods () { 30 | return http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { 31 | return method.toLowerCase() 32 | }) 33 | } 34 | 35 | /** 36 | * Get the "basic" Node.js methods, a snapshot from Node.js 0.10. 37 | * @private 38 | */ 39 | 40 | function getBasicNodeMethods () { 41 | return [ 42 | 'get', 43 | 'post', 44 | 'put', 45 | 'head', 46 | 'delete', 47 | 'options', 48 | 'trace', 49 | 'copy', 50 | 'lock', 51 | 'mkcol', 52 | 'move', 53 | 'purge', 54 | 'propfind', 55 | 'proppatch', 56 | 'unlock', 57 | 'report', 58 | 'mkactivity', 59 | 'checkout', 60 | 'merge', 61 | 'm-search', 62 | 'notify', 63 | 'subscribe', 64 | 'unsubscribe', 65 | 'patch', 66 | 'search', 67 | 'connect' 68 | ] 69 | } 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "methods", 3 | "description": "HTTP methods that node supports", 4 | "version": "1.1.2", 5 | "contributors": [ 6 | "Douglas Christopher Wilson ", 7 | "Jonathan Ong (http://jongleberry.com)", 8 | "TJ Holowaychuk (http://tjholowaychuk.com)" 9 | ], 10 | "license": "MIT", 11 | "repository": "jshttp/methods", 12 | "devDependencies": { 13 | "eslint": "4.19.1", 14 | "eslint-config-standard": "11.0.0", 15 | "eslint-plugin-import": "2.13.0", 16 | "eslint-plugin-node": "6.0.1", 17 | "eslint-plugin-promise": "3.8.0", 18 | "eslint-plugin-standard": "3.1.0", 19 | "mocha": "10.2.0", 20 | "nyc": "15.1.0" 21 | }, 22 | "files": [ 23 | "index.js", 24 | "HISTORY.md", 25 | "LICENSE" 26 | ], 27 | "engines": { 28 | "node": ">= 0.6" 29 | }, 30 | "scripts": { 31 | "lint": "eslint .", 32 | "test": "mocha --reporter spec --bail --check-leaks test/", 33 | "test-ci": "nyc --reporter=lcov --reporter=text npm test", 34 | "test-cov": "nyc --reporter=html --reporter=text npm test" 35 | }, 36 | "browser": { 37 | "http": false 38 | }, 39 | "keywords": [ 40 | "http", 41 | "methods" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /test/.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | mocha: true 3 | -------------------------------------------------------------------------------- /test/browserify.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | var browserify = tryRequire('browserify') 3 | var istanbul = tryRequire('istanbul') 4 | var methods = null 5 | var path = require('path') 6 | var run = browserify ? describe : describe.skip 7 | var stream = require('stream') 8 | var vm = require('vm') 9 | 10 | run('when browserified', function () { 11 | before(function (done) { 12 | var b = browserify() 13 | var c = {} 14 | 15 | // instrument 16 | if (istanbul && getCoverageGlobal()) { 17 | b.transform(istanbulify(c)) 18 | } 19 | 20 | // require methods 21 | b.require(path.join(__dirname, '..'), { 22 | expose: 'methods' 23 | }) 24 | 25 | // bundle and eval 26 | b.bundle(function (err, buf) { 27 | if (err) return done(err) 28 | var require = vm.runInNewContext(buf.toString(), c) 29 | methods = require('methods') 30 | done() 31 | }) 32 | }) 33 | 34 | describe('methods', function () { 35 | ['get', 'post', 'put', 'patch', 'delete'].forEach(function (method) { 36 | it('should contain "' + method + '"', function () { 37 | assert.notEqual(methods.indexOf(method), -1) 38 | }) 39 | }) 40 | 41 | it('should only have lower-case entries', function () { 42 | for (var i = 0; i < methods.length; i++) { 43 | assert(methods[i], methods[i].toLowerCase(), methods[i] + ' is lower-case') 44 | } 45 | }) 46 | }) 47 | }) 48 | 49 | function getCoverageGlobal () { 50 | for (var key in global) { 51 | if (key.substr(0, 6) === '$$cov_') { 52 | return global[key] 53 | } 54 | } 55 | } 56 | 57 | function istanbulify (context) { 58 | // link coverage 59 | context.__coverage__ = getCoverageGlobal() 60 | 61 | // browserify transform 62 | return function (file) { 63 | var chunks = [] 64 | var instrumenter = new istanbul.Instrumenter() 65 | var transformer = new stream.Transform() 66 | 67 | // buffer chunks 68 | transformer._transform = function _transform (data, encoding, callback) { 69 | chunks.push(data) 70 | callback() 71 | } 72 | 73 | // transform on flush 74 | transformer._flush = function _flush (callback) { 75 | var contents = Buffer.concat(chunks).toString() 76 | instrumenter.instrument(contents, file, function (err, output) { 77 | if (err) return transformer.emit('error', err) 78 | transformer.push(output) 79 | transformer.push(null) 80 | callback() 81 | }) 82 | } 83 | 84 | return transformer 85 | } 86 | } 87 | 88 | function tryRequire (name) { 89 | try { 90 | return require(name) 91 | } catch (e) { 92 | return undefined 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /test/methods.js: -------------------------------------------------------------------------------- 1 | var http = require('http') 2 | var assert = require('assert') 3 | var methods = require('..') 4 | 5 | describe('methods', function () { 6 | if (http.METHODS) { 7 | it('is a lowercased http.METHODS', function () { 8 | var lowercased = http.METHODS.map(function (method) { 9 | return method.toLowerCase() 10 | }) 11 | assert.deepEqual(lowercased, methods) 12 | }) 13 | } else { 14 | it('contains GET, POST, PUT, and DELETE', function () { 15 | assert.notEqual(methods.indexOf('get'), -1) 16 | assert.notEqual(methods.indexOf('post'), -1) 17 | assert.notEqual(methods.indexOf('put'), -1) 18 | assert.notEqual(methods.indexOf('delete'), -1) 19 | }) 20 | 21 | it('is all lowercase', function () { 22 | for (var i = 0; i < methods.length; i++) { 23 | assert(methods[i], methods[i].toLowerCase(), methods[i] + " isn't all lowercase") 24 | } 25 | }) 26 | } 27 | }) 28 | --------------------------------------------------------------------------------