diff --git a/CHANGELOG.md b/CHANGELOG.md index 484db93..4e0f206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,19 @@ ## [Unreleased](https://github.com/pbojinov/request-ip/tree/HEAD) -[Full Changelog](https://github.com/pbojinov/request-ip/compare/3.0.2...HEAD) +[Full Changelog](https://github.com/pbojinov/request-ip/compare/3.1.0...HEAD) + +**Closed issues:** + +- Incompatible with Next.js middleware/Vercel edge functions [\#63](https://github.com/pbojinov/request-ip/issues/63) + +## [3.1.0](https://github.com/pbojinov/request-ip/tree/3.1.0) (2022-07-06) + +[Full Changelog](https://github.com/pbojinov/request-ip/compare/v4.0.0...3.1.0) + +## [v4.0.0](https://github.com/pbojinov/request-ip/tree/v4.0.0) (2022-07-06) + +[Full Changelog](https://github.com/pbojinov/request-ip/compare/3.0.2...v4.0.0) **Merged pull requests:** diff --git a/dist/index.js b/lib/index.js similarity index 99% rename from dist/index.js rename to lib/index.js index fdb9e5c..13811b2 100644 --- a/dist/index.js +++ b/lib/index.js @@ -144,5 +144,4 @@ module.exports = { getClientIpFromXForwardedFor: getClientIpFromXForwardedFor, getClientIp: getClientIp, mw: mw -}; - +}; \ No newline at end of file diff --git a/lib/is.js b/lib/is.js new file mode 100644 index 0000000..a509378 --- /dev/null +++ b/lib/is.js @@ -0,0 +1,42 @@ +"use strict"; + +var regexes = { + ipv4: /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/, + ipv6: /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i +}; + +function not(func) { + return function () { + return !func.apply(null, Array.prototype.slice.call(arguments)); + }; +} + +function existy(value) { + return value != null; +} + +function ip(value) { + return existy(value) && regexes.ipv4.test(value) || regexes.ipv6.test(value); +} + +function object(value) { + return Object(value) === value; +} + +function string(value) { + return Object.prototype.toString.call(value) === '[object String]'; +} + +var is = { + existy: existy, + ip: ip, + object: object, + string: string, + not: { + existy: not(existy), + ip: not(ip), + object: not(object), + string: not(string) + } +}; +module.exports = is; \ No newline at end of file diff --git a/package.json b/package.json index 8750958..a1d273a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "request-ip", - "version": "3.1.0", + "version": "3.2.0", "description": "A small Node.js module to retrieve the request's IP address", "keywords": [ "request ip", @@ -49,9 +49,9 @@ "files": [ "dist" ], - "main": "./dist/index.js", + "main": "./lib/index.js", "scripts": { - "build": "babel ./src/index.js > ./dist/index.js", + "build": "babel src --out-dir lib", "changelog": "github_changelog_generator -u pbojinov -p request-ip", "coverage": "nyc report --reporter=text-lcov | coveralls", "test": "nyc --reporter=html --reporter=text --check-coverage --lines=100 --statements=100 tape ./test/*.js"