1 /*---------------------------------------------------------------------------------------------
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License. See License.txt in the project root for license information.
4 *--------------------------------------------------------------------------------------------*/
6 if (typeof module === "object" && typeof module.exports === "object") {
7 var v = factory(require, exports);
8 if (v !== undefined) module.exports = v;
10 else if (typeof define === "function" && define.amd) {
11 define(["require", "exports"], factory);
13 })(function (require, exports) {
15 Object.defineProperty(exports, "__esModule", { value: true });
16 exports.extendedRegExp = exports.repeat = exports.convertSimple2RegExpPattern = exports.endsWith = exports.startsWith = void 0;
17 function startsWith(haystack, needle) {
18 if (haystack.length < needle.length) {
21 for (var i = 0; i < needle.length; i++) {
22 if (haystack[i] !== needle[i]) {
28 exports.startsWith = startsWith;
30 * Determines if haystack ends with needle.
32 function endsWith(haystack, needle) {
33 var diff = haystack.length - needle.length;
35 return haystack.lastIndexOf(needle) === diff;
37 else if (diff === 0) {
38 return haystack === needle;
44 exports.endsWith = endsWith;
45 function convertSimple2RegExpPattern(pattern) {
46 return pattern.replace(/[\-\\\{\}\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&').replace(/[\*]/g, '.*');
48 exports.convertSimple2RegExpPattern = convertSimple2RegExpPattern;
49 function repeat(value, count) {
52 if ((count & 1) === 1) {
60 exports.repeat = repeat;
61 function extendedRegExp(pattern) {
62 if (startsWith(pattern, '(?i)')) {
63 return new RegExp(pattern.substring(4), 'i');
66 return new RegExp(pattern);
69 exports.extendedRegExp = extendedRegExp;