MCPcopy Create free account
hub / github.com/microsoft/SandDance / augment

Function augment

docs/tests/v2/es6/js/sanddance.js:139054–139082  ·  view source on GitHub ↗

* Attaches extended data and `XRegExp.prototype` properties to a regex object. * * @private * @param {RegExp} regex Regex to augment. * @param {Array} captureNames Array with capture names, or `null`. * @param {String} xSource XRegExp pattern used to generate `regex`, or `null` if N/A. * @para

(regex, captureNames, xSource, xFlags, isInternalOnly)

Source from the content-addressed store, hash-verified

139052 * @returns {RegExp} Augmented regex.
139053 */
139054function augment(regex, captureNames, xSource, xFlags, isInternalOnly) {
139055 var p = void 0;
139056
139057 regex[REGEX_DATA] = {
139058 captureNames: captureNames
139059 };
139060
139061 if (isInternalOnly) {
139062 return regex;
139063 }
139064
139065 // Can't auto-inherit these since the XRegExp constructor returns a nonprimitive value
139066 if (regex.__proto__) {
139067 regex.__proto__ = XRegExp.prototype;
139068 } else {
139069 for (p in XRegExp.prototype) {
139070 // An `XRegExp.prototype.hasOwnProperty(p)` check wouldn't be worth it here, since this
139071 // is performance sensitive, and enumerable `Object.prototype` or `RegExp.prototype`
139072 // extensions exist on `regex.prototype` anyway
139073 regex[p] = XRegExp.prototype[p];
139074 }
139075 }
139076
139077 regex[REGEX_DATA].source = xSource;
139078 // Emulate the ES6 `flags` prop by ensuring flags are in alphabetical order
139079 regex[REGEX_DATA].flags = xFlags ? xFlags.split('').sort().join('') : xFlags;
139080
139081 return regex;
139082}
139083
139084/**
139085 * Removes any duplicate characters from the provided string.

Callers 2

copyRegexFunction · 0.85
XRegExpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected