Expose dateISOify()
and toISOString()
exports.dateISOify
Hide Source
exports.dateISOify = dateISOify;
exports.toISOString = toISOString;
Expose dateISOify()
and toISOString()
exports.dateISOify = dateISOify;
exports.toISOString = toISOString;
ISOify Date
objects (possibly in collections)
function dateISOify(obj){
if( obj instanceof Array ){
for(var i = 0; i < obj.length; i++){
obj[i] = dateISOify(obj[i]);
}
}else if(obj instanceof Object && !(obj instanceof Date) ){
for(var key in obj){
if( obj[key] instanceof Date ) obj[key] = toISOString(obj[key]);
}
}else{
if( obj instanceof Date ) obj = toISOString(obj);
}
return obj;
}
ISOify a single Date
object
Sidesteps Invalid Date
objects by returning null
instead
function toISOString(date) {
return (date && !isNaN(date.getTime())) ? date.toISOString() : null;
}
Expose stringify()
exports.stringify = stringify;
Serialize an object to a string. Optionally override the default separator ('&') and assignment ('=') characters.
function stringify(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
obj = (obj === null) ? undefined : obj;
switch (typeof obj) {
case 'object':
return Object.keys(obj).map(function(k) {
if (Array.isArray(obj[k])) {
return obj[k].map(function(v) {
return stringifyPrimitive(k) +
eq +
stringifyPrimitive(v);
}).join(sep);
} else {
return stringifyPrimitive(k) +
eq +
stringifyPrimitive(obj[k]);
}
}).join(sep);
default:
if (!name) return '';
return stringifyPrimitive(name) + eq +
stringifyPrimitive(obj);
}
}
Stringify a primitive
function stringifyPrimitive(v) {
switch (typeof v) {
case 'string':
return v;
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return isFinite(v) ? v : '';
default:
return '';
}
}
Expose escapeSpecialChars
exports.escapeSpecialChars = escapeSpecialChars;
Escape special characters that are part of the query syntax of Lucene
function escapeSpecialChars(s){
return s.replace(/([\+\-!\(\)\{\}\[\]\^"~\*\?:\\])/g, function(match) {
return '\\' + match;
})
.replace(/&&/g, '\\&\\&')
.replace(/\|\|/g, '\\|\\|');
}