From 30c6111371aedbf717c9ac24a40706bae537b49a Mon Sep 17 00:00:00 2001 From: deltreey Date: Tue, 4 Aug 2015 00:49:17 -0400 Subject: [PATCH] Good Documentation --- README.md | 6 + documentation/F__Git_wildstring_index.js.html | 336 +++++++ documentation/classes.list.html | 241 +++++ documentation/global.html | 798 +++++++++++++++++ documentation/index.html | 15 +- documentation/namespaces.list.html | 241 +++++ documentation/wildstring.html | 837 ++++++++++++++++++ index.js | 30 +- jsdoc.conf.json | 2 +- 9 files changed, 2501 insertions(+), 5 deletions(-) create mode 100644 documentation/F__Git_wildstring_index.js.html create mode 100644 documentation/classes.list.html create mode 100644 documentation/global.html create mode 100644 documentation/namespaces.list.html create mode 100644 documentation/wildstring.html diff --git a/README.md b/README.md index 26fa0bd..3af92e6 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,9 @@ 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](http://deltreey.github.io/wildstring) + +Repository: [https://github.com/deltreey/wildstring](https://github.com/deltreey/wildstring) diff --git a/documentation/F__Git_wildstring_index.js.html b/documentation/F__Git_wildstring_index.js.html new file mode 100644 index 0000000..4e40bf9 --- /dev/null +++ b/documentation/F__Git_wildstring_index.js.html @@ -0,0 +1,336 @@ + + + + + + wildstring Source: F:/Git/wildstring/index.js + + + + + + + + + + + + + +
+
+ + +
+ +
+

Source: F:/Git/wildstring/index.js

+ + +

Source: F:/Git/wildstring/index.js

+ +
+
+
'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 < rollbackStrings.length; ++s) {
+		var currentString = rollbackStrings[s].string;	// starting with the rolled back string
+		var patternIndex = rollbackStrings[s].index;
+
+		while (patternIndex < 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] !== '' &&
+					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 && string.indexOf(patternSubstrings[0]) !== 0) {
+		// not starting with a wildcard
+		return false;
+	}
+
+	var rollbackStrings = [];
+
+	while (patternIndex < 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 &&
+			patternSubstrings[patternSubstrings.length - 1] !== '' &&
+			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 < strings.length; ++s) {
+		result += patternSubstrings[s] + strings[s];
+	}
+
+	return result;
+};
+
+module.exports = wildstring;
+return wildstring;
+}(module || {}));
+
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + diff --git a/documentation/classes.list.html b/documentation/classes.list.html new file mode 100644 index 0000000..753a9f9 --- /dev/null +++ b/documentation/classes.list.html @@ -0,0 +1,241 @@ + + + + + + wildstring Classes + + + + + + + + + + + + + +
+
+ + +
+ +
+

Classes

+ + +

Classes

+
+ +
+ +

+ +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + +

Classes

+ +
+
wildstring
+
+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+
+ +
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/documentation/global.html b/documentation/global.html new file mode 100644 index 0000000..0b98d85 --- /dev/null +++ b/documentation/global.html @@ -0,0 +1,798 @@ + + + + + + wildstring Global + + + + + + + + + + + + + +
+
+ + +
+ +
+

Global

+ + +

Global

+
+ +
+ +

+ +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+

<private> wildstring.checkRollbackStrings +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(rollbackStrings, patternSubstrings)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rollbackStrings + + +Array.<string> + + + +

The list of substrings that appeared prior to the current match

patternSubstrings + + +Array.<string> + + + +

The matching list of pattens that need to be matched before the current pattern

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+

wildstring.match +Check if a string matches a pattern(pattern, string)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pattern + + +string + + + +

The pattern to match using the configured wildcard

string + + +string + + + +

The string to test for a match

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+

wildstring.replace +Replace wildcards in a pattern with strings (string interpolation)(pattern, strings)

+ + +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pattern + + +string + + + +

The start string, using wildcards as placeholders

strings + + +string +| + +Array.<string> + + + +

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.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+
    +
  • + +
    +
    +
    +

    The number of items in the strings array (if you pass an array) must match the number of wildcards in the pattern string.

    +
    +
    +
    +
    +
    + Type +
    +
    + +Error + + +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    You need to pass both parameters

    +
    +
    +
    +
    +
    + Type +
    +
    + +Error + + +
    +
    +
    +
    + +
  • + +
  • + +
    +
    +
    +

    You need to pass the right types

    +
    +
    +
    +
    +
    + Type +
    +
    + +Error + + +
    +
    +
    +
    + +
  • +
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/documentation/index.html b/documentation/index.html index 8ad3384..2961e52 100644 --- a/documentation/index.html +++ b/documentation/index.html @@ -10,7 +10,7 @@ - + @@ -24,6 +24,13 @@ @@ -96,7 +103,9 @@ wildstring.match('tEsT', 'TeSt'); // true, 'test' matches
git clone https://github.com/deltreey/wildstring
 # npm install -g grunt-cli # if you don't have it
 npm install
-grunt

grunt will run all the tests and jshint, so just make sure it passes before submitting a pull request

+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

@@ -130,7 +139,7 @@ grunt

grunt will run all the tests and jshint, so just make sure Documentation generated by JSDoc 3.3.2 - on Mon Aug 3rd 2015 using the DocStrap template. diff --git a/documentation/namespaces.list.html b/documentation/namespaces.list.html new file mode 100644 index 0000000..074abfd --- /dev/null +++ b/documentation/namespaces.list.html @@ -0,0 +1,241 @@ + + + + + + wildstring Namespaces + + + + + + + + + + +

+ + +
+
+ + +
+ +
+

Namespaces

+ + +

Namespaces

+
+ +
+ +

+ +

+ + +
+ + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + +

Namespaces

+ +
+
wildstring
+
+
+ + + + + + + + + +
+ +
+ + + + +
+
+ +
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/documentation/wildstring.html b/documentation/wildstring.html new file mode 100644 index 0000000..f3c9b29 --- /dev/null +++ b/documentation/wildstring.html @@ -0,0 +1,837 @@ + + + + + + wildstring Namespace: wildstring + + + + + + + + + + + + + +
+
+ + +
+ +
+

Namespace: wildstring

+ + +

Namespace: wildstring

+
+ +
+ +

+ wildstring +

+ + +
+ + +
+
+ + + + +
+ + +
Properties:
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
wildcard + + +string + + + +

the wildcard to use in your strings, defaults to '*'

caseSensitive + + +boolean + + + +

whether matches should care about case, defaults to true

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + +

Methods

+ +
+ +
+

<private, static> checkRollbackStrings(rollbackStrings, patternSubstrings)

+ + +
+
+ + +
+

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

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
rollbackStrings + + +Array.<string> + + + +

The list of substrings that appeared prior to the current match

patternSubstrings + + +Array.<string> + + + +

The matching list of pattens that need to be matched before the current pattern

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+

<static> match(pattern, string)

+ + +
+
+ + +
+

Check if a string matches a pattern

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pattern + + +string + + + +

The pattern to match using the configured wildcard

string + + +string + + + +

The string to test for a match

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+

<static> replace(pattern, strings)

+ + +
+
+ + +
+

Replace wildcards in a pattern with strings (string interpolation)

+
+ + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
pattern + + +string + + + +

The start string, using wildcards as placeholders

strings + + +string +| + +Array.<string> + + + +

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.

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+
    +
  • + +
    + +

    The number of items in the strings array (if you pass an array) must match the number of wildcards in the pattern string.

    + +
    + +
  • + +
  • + +
    + +

    You need to pass both parameters

    + +
    + +
  • + +
  • + +
    + +

    You need to pass the right types

    + +
    + +
  • +
+ + + + +
+ +
+ + + + + +
+ +
+ + + + +
+
+ +
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js index 5fba4ec..aa82ae3 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,23 @@ 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 < rollbackStrings.length; ++s) { var currentString = rollbackStrings[s].string; // starting with the rolled back string @@ -49,6 +61,12 @@ function checkRollbackStrings (rollbackStrings, patternSubstrings) { 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) { @@ -115,7 +133,17 @@ wildstring.match = function (pattern, string) { 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.'); diff --git a/jsdoc.conf.json b/jsdoc.conf.json index f5c2449..efb4d9f 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -13,7 +13,7 @@ "footer": "", "copyright": "DocStrap Copyright © 2012-2014 The contributors to the JSDoc3 and DocStrap projects.", "navType": "vertical", - "theme": "cosmo", + "theme": "simplex", "linenums": true, "collapseSymbols": false, "inverseNav": true,