[79a0317] | 1 | # wildcard
|
---|
| 2 |
|
---|
| 3 | Very simple wildcard matching, which is designed to provide the same
|
---|
| 4 | functionality that is found in the
|
---|
| 5 | [eve](https://github.com/adobe-webplatform/eve) eventing library.
|
---|
| 6 |
|
---|
| 7 | [![NPM](https://nodei.co/npm/wildcard.png)](https://nodei.co/npm/wildcard/)
|
---|
| 8 |
|
---|
| 9 | [![stable](https://img.shields.io/badge/stability-stable-green.svg)](https://github.com/dominictarr/stability#stable)
|
---|
| 10 |
|
---|
| 11 | ## Usage
|
---|
| 12 |
|
---|
| 13 | It works with strings:
|
---|
| 14 |
|
---|
| 15 | ```js
|
---|
| 16 | var wildcard = require('wildcard');
|
---|
| 17 |
|
---|
| 18 | console.log(wildcard('foo.*', 'foo.bar'));
|
---|
| 19 | // --> true
|
---|
| 20 |
|
---|
| 21 | console.log(wildcard('foo.*', 'foo'));
|
---|
| 22 | // --> true
|
---|
| 23 | ```
|
---|
| 24 |
|
---|
| 25 | Arrays:
|
---|
| 26 |
|
---|
| 27 | ```js
|
---|
| 28 | var wildcard = require('wildcard');
|
---|
| 29 | var testdata = [
|
---|
| 30 | 'a.b.c',
|
---|
| 31 | 'a.b',
|
---|
| 32 | 'a',
|
---|
| 33 | 'a.b.d'
|
---|
| 34 | ];
|
---|
| 35 |
|
---|
| 36 | console.log(wildcard('a.b.*', testdata));
|
---|
| 37 | // --> ['a.b.c', 'a.b', 'a.b.d']
|
---|
| 38 | ```
|
---|
| 39 |
|
---|
| 40 | Objects (matching against keys):
|
---|
| 41 |
|
---|
| 42 | ```js
|
---|
| 43 | var wildcard = require('wildcard');
|
---|
| 44 | var testdata = {
|
---|
| 45 | 'a.b.c' : {},
|
---|
| 46 | 'a.b' : {},
|
---|
| 47 | 'a' : {},
|
---|
| 48 | 'a.b.d' : {}
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | console.log(wildcard('a.*.c', testdata));
|
---|
| 52 | // --> { 'a.b.c': {} }
|
---|
| 53 | ```
|
---|
| 54 |
|
---|
| 55 | ## Alternative Implementations
|
---|
| 56 |
|
---|
| 57 | * <https://github.com/isaacs/node-glob>
|
---|
| 58 |
|
---|
| 59 | Great for full file-based wildcard matching.
|
---|
| 60 |
|
---|
| 61 | * <https://github.com/sindresorhus/matcher>
|
---|
| 62 |
|
---|
| 63 | A well cared for and loved JS wildcard matcher.
|
---|
| 64 |
|
---|
| 65 | ## License(s)
|
---|
| 66 |
|
---|
| 67 | ### MIT
|
---|
| 68 |
|
---|
| 69 | Copyright (c) 2023 Damon Oehlman <mailto:damon.oehlman@gmail.com>
|
---|
| 70 |
|
---|
| 71 | Permission is hereby granted, free of charge, to any person obtaining
|
---|
| 72 | a copy of this software and associated documentation files (the
|
---|
| 73 | 'Software'), to deal in the Software without restriction, including
|
---|
| 74 | without limitation the rights to use, copy, modify, merge, publish,
|
---|
| 75 | distribute, sublicense, and/or sell copies of the Software, and to
|
---|
| 76 | permit persons to whom the Software is furnished to do so, subject to
|
---|
| 77 | the following conditions:
|
---|
| 78 |
|
---|
| 79 | The above copyright notice and this permission notice shall be
|
---|
| 80 | included in all copies or substantial portions of the Software.
|
---|
| 81 |
|
---|
| 82 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
---|
| 83 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
---|
| 84 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
---|
| 85 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
---|
| 86 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
---|
| 87 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
---|
| 88 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
---|