Simple String Wildcard Handling
Shake it shake it
Installing wildstring is a snap. wildstring has no dependencies, so you don't need anything else to run it. If you want to use tools though, here's some tips on how to install it with popular installers.
node.js
npm install wildstring
then:
var wildstring = require('wildstring');
bower
bower install wildstring
html
<script src="wildstring.js"></script>
Hold me tight
Especially with something that does something new, it's important to see how it works. Below are some examples, but here's a brief explanation as well.
In this explanation, I'll use *
as my wildcard for simplicity. If you put a wildcard at the beginning, for example *Thing
then you can match anything or nothing before your string. So your string could be Wild Thing
or just Thing
and it would match fine. The same is true for the end. Wild*
would match Wild Thing
or just Wild
. If you want to match text in the middle of the string, it works the same way. Wild*Thing
matches both WildThing
and Wild and crazy Thing
.
wildstring.match('Test*', 'Testing');
wildstring.match('*ing', 'testing');
wildstring.match('Test*', 'Test');
wildstring.match('*ing', 'Testing it');
wildstring.match('Test', 'Testing');
wildstring.match('Test*ing', 'Testing this thing');
wildstring.match('*))))))*', ')))))');
You make my heart string
You can use wildstring for string interpolation, which makes for an easier interface to parse data from users who maybe don't know regular expressions.
wildstring.replace('I * node.*', [ 'love', 'js' ]);
wildstring.replace('I * node.*', 'script');
wildstring.replace('I * node.*', [ 'love' ]);
wildstring.replace('*/*/*', [ new Date.getMonth() + 1, new Date.getDate(), new Date.getFullYear]);
You make everything, groovy
You can use your own wildcards with wildstring, so you can wildstring everything. You can even turn off case sensitive matching if you want.
wildstring.wildcard = 'stuff';
wildstring.match('Test stuff', 'Test wild');
wildstring.replace('stuff and stuffthings', [ 'WILD', 'thing' ]);
wildstring.caseSensitive = false;
wildstring.match('tEsT', 'TeSt');
I think I love you
If you want to contribute to wildstring, it's really easy. Just make sure you have nodejs installed and do the following.
git clone https://github.com/deltreey/wildstring
npm install
grunt
grunt will run all the tests and jshint, so just make sure it passes before submitting a pull request
But I wanna know for sure
Documentation: http://deltreey.github.io/wildstring
Repository: https://github.com/deltreey/wildstring