rename index.js to wildstring.js

semver requires a major version bump
This commit is contained in:
deltreey
2015-08-04 00:55:01 -04:00
parent 30c6111371
commit d203b3e662
8 changed files with 349 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ module.exports = function (grunt) {
},
jsdoc: {
dist: {
src: ['index.js', 'test/*.js', 'README.md'],
src: ['wildstring.js', 'test/*.js', 'README.md'],
options: {
destination: 'documentation',
template : 'node_modules/grunt-jsdoc/node_modules/ink-docstrap/template',

View File

@@ -29,7 +29,6 @@ bower install wildstring
#### html
make sure you rename the `index.js` file to `wildstring.js` when you add it to your project
``` html
<script src="wildstring.js"></script>
```

View File

@@ -1,6 +1,6 @@
{
"name": "wildstring",
"main": "index.js",
"main": "wildstring.js",
"version": "0.0.2",
"authors": [
"deltreey <suicidolt@gmail.com>"

View File

@@ -0,0 +1,336 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>wildstring Source: F:/Git/wildstring/wildstring.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">wildstring</a>
</div>
<div class="navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="wildstring.html">wildstring</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="main">
<h1 class="page-title">Source: F:/Git/wildstring/wildstring.js</h1>
<h1 class="page-title">Source: F:/Git/wildstring/wildstring.js</h1>
<section>
<article>
<pre
class="sunlight-highlight-javascript linenums">'use strict';
var wildstring = (function(module) {
/**
* @namespace wildstring
* @property {string} wildcard the wildcard to use in your strings, defaults to '*'
* @property {boolean} caseSensitive whether matches should care about case, defaults to true
*/
wildstring = {
wildcard: '*',
caseSensitive: true
};
/**
* When a match doesn't continue to the end of the string, this function rolls back to try again with the rest of the string
* @memberof wildstring
* @access private
* @param {string[]} rollbackStrings The list of substrings that appeared prior to the current match
* @param {string[]} patternSubstrings The matching list of pattens that need to be matched before the current pattern
*/
function checkRollbackStrings (rollbackStrings, patternSubstrings) {
for (var s = 0; s &lt; rollbackStrings.length; ++s) {
var currentString = rollbackStrings[s].string; // starting with the rolled back string
var patternIndex = rollbackStrings[s].index;
while (patternIndex &lt; patternSubstrings.length) {
if (currentString.indexOf(patternSubstrings[patternIndex]) === -1) {
break;
}
var testString = currentString.substr(1); //remove just one char to retest
rollbackStrings.push({ string: testString, index: patternIndex });
if (testString.indexOf(patternSubstrings[patternIndex]) === -1) {
rollbackStrings.pop();
break;
}
currentString = currentString.substr(
currentString.indexOf(patternSubstrings[patternIndex]) + patternSubstrings[patternIndex].length
);
patternIndex++;
while (patternSubstrings[patternIndex] === '') {
patternIndex++;
}
if (patternIndex >= patternSubstrings.length) {
if (patternSubstrings[patternSubstrings.length - 1] !== '' &amp;&amp;
currentString.length > 0) {
// not ending with a wildcard, we need to backtrack
break;
}
else {
return true;
}
}
}
}
return false;
}
/**
* Check if a string matches a pattern
* @memberof wildstring
* @param {string} pattern The pattern to match using the configured wildcard
* @param {string} string The string to test for a match
*/
wildstring.match = function (pattern, string) {
// if there are no wildcards, must be exact
if (pattern.indexOf(wildstring.wildcard) === -1) {
return pattern === string;
}
if (!wildstring.caseSensitive) {
pattern = pattern.toLowerCase();
string = string.toLowerCase();
}
var patternSubstrings = pattern.split(wildstring.wildcard);
var patternIndex = 0;
var currentString = string;
// find pattern beginning
while (patternSubstrings[patternIndex] === '') {
patternIndex++;
// if the pattern is just wildcards, it matches
if (patternIndex === pattern.length) {
return true;
}
}
if (patternIndex === 0 &amp;&amp; string.indexOf(patternSubstrings[0]) !== 0) {
// not starting with a wildcard
return false;
}
var rollbackStrings = [];
while (patternIndex &lt; patternSubstrings.length) {
if (currentString.indexOf(patternSubstrings[patternIndex]) === -1) {
return checkRollbackStrings(rollbackStrings, patternSubstrings);
}
// create a queue of strings to roll back and try again if we fail later
var testString = currentString.substr(1); //remove just one char to retest
rollbackStrings.push({ string: testString, index: patternIndex });
if (testString.indexOf(patternSubstrings[patternIndex]) === -1) {
rollbackStrings.pop();
}
currentString = currentString.substr(
currentString.indexOf(patternSubstrings[patternIndex]) + patternSubstrings[patternIndex].length
);
patternIndex++;
while (patternSubstrings[patternIndex] === '') {
patternIndex++;
}
}
if (patternIndex >= patternSubstrings.length &amp;&amp;
patternSubstrings[patternSubstrings.length - 1] !== '' &amp;&amp;
currentString.length > 0) {
// not ending with a wildcard, we need to backtrack
if (currentString === string) { // this string doesn't even match a little
return false;
}
return checkRollbackStrings(rollbackStrings, patternSubstrings);
}
return true;
};
/**
* Replace wildcards in a pattern with strings (string interpolation)
* @memberof wildstring
* @param {string} pattern The start string, using wildcards as placeholders
* @param {string|string[]} strings The string or strings to replace the wildcards in the pattern.
* If you pass a single string, it will replace all the wildcards with the string.
* If you pass an array of strings, they will replace the wildcards in order from left to right.
* @throws The number of items in the strings array (if you pass an array) must match the number of wildcards in the pattern string.
* @throws You need to pass both parameters
* @throws You need to pass the right types
*/
wildstring.replace = function (pattern, strings) {
if (pattern === undefined || strings === undefined) {
throw new Error('wildstring.replace takes the pattern as one parameter and either a string or an array of strings as the second. You didn\'t pass enough parameters.');
}
if (typeof(strings) === typeof('')) {
return pattern.replace(wildstring.wildcard, strings);
}
if (!Array.isArray(strings) || typeof(pattern) !== typeof('')) {
throw new Error('wildstring.replace takes the pattern as one parameter and either a string or an array of strings as the second. Your parameter types are incorrect.');
}
if (pattern.indexOf(wildstring.wildcard) === -1) {
return pattern; // if there are no wildcards, just return the pattern
}
var patternSubstrings = pattern.split(wildstring.wildcard);
if (patternSubstrings.length - 1 !== strings.length) {
var message = 'There are a different number of wildcards than strings to replace them. You have ' +
wildstring.wildcard +' wildcards in "' + wildstring.wildcard + '" and ' + wildstring.wildcard +
' replacement strings.';
throw new Error(wildstring.replace(message, [ patternSubstrings.length - 1, pattern, strings.length ]));
}
var result = '';
for (var s = 0; s &lt; strings.length; ++s) {
result += patternSubstrings[s] + strings[s];
}
return result;
};
module.exports = wildstring;
return wildstring;
}(module || {}));
</pre>
</article>
</section>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<footer>
<span class="copyright">
DocStrap Copyright © 2012-2014 The contributors to the JSDoc3 and DocStrap projects.
</span>
<br />
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a>
on Tue Aug 4th 2015 using the <a
href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
</span>
</footer>
<!--<script src="scripts/sunlight.js"></script>-->
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/bootstrap-dropdown.js"></script>
<script src="scripts/toc.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : "100px"
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );
$( ".tutorial-section pre, .readme-section pre" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
lang = "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
} );
</script>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
</body>
</html>

View File

@@ -79,8 +79,7 @@
<a href="https://gitter.im/deltreey/wildstring?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Join the chat at https://gitter.im/deltreey/wildstring"></a></p>
<h2>Shake it shake it</h2><p>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.</p>
<h4>node.js</h4><pre class="prettyprint source lang-bash"><code>npm install wildstring</code></pre><p>then:</p>
<pre class="prettyprint source lang-js"><code>var wildstring = require('wildstring');</code></pre><h4>bower</h4><pre class="prettyprint source lang-bash"><code>bower install wildstring</code></pre><h4>html</h4><p>make sure you rename the <code>index.js</code> file to <code>wildstring.js</code> when you add it to your project</p>
<pre class="prettyprint source lang-html"><code>&lt;script src=&quot;wildstring.js&quot;>&lt;/script></code></pre><h2>Hold me tight</h2><p>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.</p>
<pre class="prettyprint source lang-js"><code>var wildstring = require('wildstring');</code></pre><h4>bower</h4><pre class="prettyprint source lang-bash"><code>bower install wildstring</code></pre><h4>html</h4><pre class="prettyprint source lang-html"><code>&lt;script src=&quot;wildstring.js&quot;>&lt;/script></code></pre><h2>Hold me tight</h2><p>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.</p>
<p>In this explanation, I'll use <code>*</code> as my wildcard for simplicity. If you put a wildcard at the beginning, for example <code>*Thing</code> then you can match anything or nothing before your string. So your string could be <code>Wild Thing</code> or just <code>Thing</code> and it would match fine. The same is true for the end. <code>Wild*</code> would match <code>Wild Thing</code> or just <code>Wild</code>. If you want to match text in the middle of the string, it works the same way. <code>Wild*Thing</code> matches both <code>WildThing</code> and <code>Wild and crazy Thing</code>.</p>
<pre class="prettyprint source lang-js"><code>wildstring.match('Test*', 'Testing'); // true, wildcard matches 'ing'
wildstring.match('*ing', 'testing'); // true, wildcard matches 'test'

View File

@@ -175,8 +175,8 @@
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="F__Git_wildstring_index.js.html">F:/Git/wildstring/index.js</a>,
<a href="F__Git_wildstring_index.js.html#sunlight-1-line-5">line 5</a>
<a href="F__Git_wildstring_wildstring.js.html">F:/Git/wildstring/wildstring.js</a>,
<a href="F__Git_wildstring_wildstring.js.html#sunlight-1-line-5">line 5</a>
</li>
</ul>
</dd>
@@ -338,8 +338,8 @@
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="F__Git_wildstring_index.js.html">F:/Git/wildstring/index.js</a>,
<a href="F__Git_wildstring_index.js.html#sunlight-1-line-22">line 22</a>
<a href="F__Git_wildstring_wildstring.js.html">F:/Git/wildstring/wildstring.js</a>,
<a href="F__Git_wildstring_wildstring.js.html#sunlight-1-line-22">line 22</a>
</li>
</ul>
</dd>
@@ -497,8 +497,8 @@
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="F__Git_wildstring_index.js.html">F:/Git/wildstring/index.js</a>,
<a href="F__Git_wildstring_index.js.html#sunlight-1-line-70">line 70</a>
<a href="F__Git_wildstring_wildstring.js.html">F:/Git/wildstring/wildstring.js</a>,
<a href="F__Git_wildstring_wildstring.js.html#sunlight-1-line-70">line 70</a>
</li>
</ul>
</dd>
@@ -661,8 +661,8 @@
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="F__Git_wildstring_index.js.html">F:/Git/wildstring/index.js</a>,
<a href="F__Git_wildstring_index.js.html#sunlight-1-line-147">line 147</a>
<a href="F__Git_wildstring_wildstring.js.html">F:/Git/wildstring/wildstring.js</a>,
<a href="F__Git_wildstring_wildstring.js.html#sunlight-1-line-147">line 147</a>
</li>
</ul>
</dd>

View File

@@ -1,8 +1,8 @@
{
"name": "wildstring",
"version": "0.0.3",
"version": "1.0.0",
"description": "Simple String Wildcard Handling",
"main": "index.js",
"main": "wildstring.js",
"scripts": {
"test": "grunt"
},