recital / packages / ext-common-commands / dist / lib / tools / text-tools.js
text-tools.js
Raw
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseWikiLink = exports.slugify = void 0;
var slugify = function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    var value = args.join(' ');
    return value
        .normalize('NFD') // split an accented letter in the base letter and the accent
        .replace(/[\u0300-\u036f]/g, '') // remove all previously split accents
        .toLowerCase()
        .trim()
        .replace(/[^a-z0-9 ]/g, '') // remove all chars not letters, numbers and spaces (to be replaced)
        .replace(/\s+/g, '-'); // separator
};
exports.slugify = slugify;
/**
 *
 * @param wikiLink the string of the link within the `[[]]`
 */
var parseWikiLink = function (wikiLink) {
    var label = wikiLink;
    var target = wikiLink;
    // display|target format
    var barIndex = wikiLink.indexOf('|');
    if (barIndex !== -1) {
        label = wikiLink.substring(0, barIndex);
        target = wikiLink.substring(barIndex + 1);
    }
    else {
        // display->target format
        var rightArrIndex = wikiLink.indexOf('->');
        if (rightArrIndex !== -1) {
            label = wikiLink.substring(0, rightArrIndex);
            target = wikiLink.substring(rightArrIndex + 2);
        }
        else {
            // target<-display format
            var leftArrIndex = wikiLink.indexOf('<-');
            if (leftArrIndex !== -1) {
                label = wikiLink.substring(leftArrIndex + 2);
                target = wikiLink.substring(0, leftArrIndex);
            }
        }
    }
    return {
        label: label,
        target: target,
    };
};
exports.parseWikiLink = parseWikiLink;
//# sourceMappingURL=text-tools.js.map