diffusion
Version:
Diffusion JavaScript client
54 lines (47 loc) • 1.12 kB
JavaScript
/*eslint valid-jsdoc: "off"*/
/**
* The topic path separator character.
*/
var PATH_SEPARATOR = '/';
/**
* Split a path into parts.
*
* @param path the path
* @return the parts;
*/
function split(path) {
return path.split(PATH_SEPARATOR);
}
/**
* Provide a canonical representation of a given path, stripping leading and
* trailing path separators
*
* @param {String} path
* @returns {String} The canonicalised path
*/
function canonicalise(path) {
if (!path) {
return "";
}
var l = path.length,
s = l > 0 && path.charAt(0) === PATH_SEPARATOR ? 1 : 0,
e = l > 1 && path.charAt(l - 1) === PATH_SEPARATOR ? 1 : 0;
return path.substring(s, l - e);
}
/**
* Minimal representation of DescendantQualifier enum type.
*/
function DQ(descendants) {
this.includesDescendants = descendants;
}
var qualifiers = {
MATCH: new DQ(false),
DESCENDANTS_OF_MATCH: new DQ(true),
MATCH_AND_DESCENDANTS: new DQ(true)
};
module.exports = {
split: split,
canonicalise: canonicalise,
PATH_SEPARATOR: PATH_SEPARATOR,
DescendantQualifier: qualifiers
};