Package Exports
- ip-filter
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ip-filter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ip-filter

Validates valid IPs (IPv4 and IPv6) using micromatch - glob patterns, RegExp, string or array of globs. If match returns the IP, otherwise null.
You might also be interested in is-match-ip, to-object-path, to-file-path or koa-ip-filter.
Install
npm i ip-filter --saveUsage
For more use-cases see the tests
const ipFilter = require('ip-filter')ipFilter
Filter
ipagainst globpatterns, using micromatch under the hood, sooptionsare passed to it.
Params
ip{String}: Accepts only valid IPs by defaultpatterns{String|Array|RegExp|Function|Object}: Basically everything that is-match can accept.options{Object}: Passstrict: falseif want to validate non-ip values, also passed to is-match.returns{String|null}: If not match returnsnull, otherwise the passedip.
Example
var ipFilter = require('ip-filter')
console.log(ipFilter('123.77.34.89', '123.??.34.8*')) // => '123.77.34.89'
console.log(ipFilter('123.222.34.88', '123.??.34.8*')) // => null
console.log(ipFilter('123.222.33.1', ['123.*.34.*', '*.222.33.*'])) // => '123.222.33.1'
// should notice the difference
console.log(ipFilter('123.222.34.88', ['123.*.34.*', '!123.222.**']))
// => null
console.log(ipFilter('123.222.34.88', ['123.*.34.*', '!123.222.*']))
// => '123.222.34.88'
//
// NON-STRICT mode
//
var res = ipFilter('x-koaip', ['*-koaip', '!foo-koa*'], { strict: false })
console.log(res) // => 'x-koaip'
var res = ipFilter('x-koa.foo', ['*-koa.*', '!foo-koa.*'], { strict: false })
console.log(res) // => 'x-koa.foo'Related
- ip-regex: Regular expression for matching IP addresses | homepage
- is-match-ip: Matching IPs using micromatch and ip-filter - glob patterns, RegExp, string… more | homepage
- is-match: Create a matching function from a glob pattern, regex, string, array… more | homepage
- koa-ip-filter: koa middleware to filter request IPs or custom ID with glob… more | homepage
- micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to… more | homepage
- to-file-path: Create a filepath from an object path (dot notation), list of… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.