Commit 1d416fef authored by Tristan Cavelier's avatar Tristan Cavelier

queries: tool moved to static method

parent bc1e8a99
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global newClass: true, sortFunction: true, parseStringToObject: true,
_export: true */
_export: true, stringEscapeRegexpCharacters: true */
/**
* The query to use to filter a list of objects.
......@@ -141,7 +141,23 @@ var Query = newClass(function (spec) {
* @param {String} string The string to parse
* @return {Object} The json query tree
*/
"parseStringToObject": parseStringToObject
"parseStringToObject": parseStringToObject,
/**
* Convert a search text to a regexp.
*
* @method convertStringToRegExp
* @static
* @param {String} string The string to convert
* @param {String} [wildcard_character=undefined] The wildcard chararter
* @return {RegExp} The search text regexp
*/
"convertStringToRegExp": function (string, wildcard_character) {
return new RegExp("^" + stringEscapeRegexpCharacters(string).replace(
stringEscapeRegexpCharacters(wildcard_character),
'.*'
) + "$");
}
}});
_export("Query", Query);
......@@ -109,21 +109,15 @@ function stringEscapeRegexpCharacters(string) {
}
}
_export("stringEscapeRegexpCharacters", stringEscapeRegexpCharacters);
/**
* Convert a search text to a regexp.
* A sort function to sort items by key
*
* @param {String} string The string to convert
* @param {String} [wildcard_character=undefined] The wildcard chararter
* @return {RegExp} The search text regexp
* @param {String} key The key to sort on
* @param {String} [way="ascending"] 'ascending' or 'descending'
* @return {Function} The sort function
*/
function convertSearchTextToRegExp(string, wildcard_character) {
return new RegExp("^" + stringEscapeRegexpCharacters(string).replace(
stringEscapeRegexpCharacters(wildcard_character),
'.*'
) + "$");
}
// XXX
function sortFunction(key, way) {
if (way === 'descending') {
return function (a, b) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment