Good Documentation
This commit is contained in:
30
index.js
30
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.');
|
||||
|
||||
Reference in New Issue
Block a user