plotly.js
Version:
The open source javascript graphing library that powers plotly
22 lines (21 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.counter = counter;
const NUMBER_REGEX = '([2-9]|[1-9][0-9]+)?';
/**
* make a regex for matching counter ids/names ie xaxis, xaxis2, xaxis10...
*
* @param head - the head of the pattern, eg 'x' matches 'x', 'x2', 'x10' etc.
* 'xy' is a special case for cartesian subplots: it matches 'x2y3' etc
* @param tail - a fixed piece after the id
* eg counterRegex('scene', '.annotations') for scene2.annotations etc.
* @param openEnded - if true, the string may continue past the match.
* @param matchBeginning - if false, the string may start before the match.
*/
function counter(head, tail = '', openEnded, matchBeginning) {
const fullTail = tail + (openEnded ? '' : '$');
const startWithPrefix = matchBeginning === false ? '' : '^';
return head === 'xy'
? new RegExp(startWithPrefix + 'x' + NUMBER_REGEX + 'y' + NUMBER_REGEX + fullTail)
: new RegExp(startWithPrefix + head + NUMBER_REGEX + fullTail);
}