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