UNPKG

lincd

Version:

LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)

33 lines 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.URI = void 0; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ class URI { /** * Function: sanitize * Returns a sanitized string, typically for URLs. * * Parameters: * $string - The string to sanitize. * $force_lowercase - Force the string to lowercase? */ static sanitize(string, force_lowercase = true) { if (!string) return string; //\u200B is the ZERO WIDTH SPACE, often introduced by WYSIWYG editors. This causes a hyphen (-) at the end of a string sometimes, so we filter it out first return string .replace(/\u200B/g, '') .replace(/[^\w]+/g, '-') .toLowerCase(); } static isURI(uri) { //must have a scheme followed by :// return /([A-Za-z][A-Za-z0-9+\-.]*)\:\/\//.test(uri); } } exports.URI = URI; //# sourceMappingURL=URI.js.map