How to use resolveInjections method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

index.js

Source: index.js Github

copy
1'use strict';
2
3var flatten = require('arr-flatten');
4var args = require('fn-args');
5var methods = require('methods');
6var asyncLib = require('async');
7var Dag = require('dag');
8var needInject = require('./utils.js').needInject;
9
10module.exports = function (app) {
11	var dag = new Dag();
12	var inject = function (dependency, fn) {
13		if (typeof fn !== 'function') {
14			throw new Error('inject() requires a function, but got a ' + typeof fn);
15		}
16
17		args(fn).forEach(function (param) {
18			dag.addEdge(dependency, param);
19		});
20
21		inject.declare(dependency, fn);
22	};
23
24	inject.dependencies = {};
25
26	inject.declare = function declare(name, fn) {
27		this.dependencies[name] = fn;
28	};
29
30	inject.resolve = function resolve(name, cb) {
31		var resolved = this.dependencies[name];
32		if (!resolved) {
33			return cb(new Error('Unknown dependency: ' + name));
34		}
35		return cb(null, resolved);
36	};
37
38	function resolveInjections(params, req, res, next, done) {
39		asyncLib.map(params, function (dependency, callback) {
40			if (dependency === 'req') {
41				return callback(null, req);
42			}
43			if (dependency === 'res') {
44				return callback(null, res);
45			}
46			if (dependency === 'next') {
47				return callback(null, next);
48			}
49
50			inject.resolve(dependency, function (err, constructor) {
51				if (err) {
52					throw err;
53				}
54
55				resolveInjections(
56					args(constructor),
57					req,
58					res,
59					callback,
60					function (err, results) {
61						if (err) {
62							return done(err);
63						}
64						constructor.apply(null, results);
65					}
66				);
67			});
68		}, done);
69	}
70
71	app.lazyrouter();
72
73	var _route = app._router.route.bind(app._router);
74	app._router.route = function (path) {
75		var route = _route(path);
76		methods.forEach(function (method) {
77			route[method] = wrap(route[method]);
78		});
79		return route;
80	};
81
82	function wrap(origin) {
83		return function () {
84			var callbacks = flatten([].slice.call(arguments));
85			callbacks = callbacks.map(function (fn) {
86				if (typeof fn !== 'function') {
87					return fn;
88				}
89				var params = args(fn);
90
91				if (!needInject(params)) {
92					return fn;
93				}
94
95				return function (req, res, next) {
96					resolveInjections(params, req, res, next, function (err, results) {
97						if (err) {
98							return next(err);
99						}
100						fn.apply(null, results);
101					});
102				};
103			});
104
105			origin.call(this, callbacks);
106		};
107	}
108
109	return inject;
110};
111
Full Screen

medic-injector-sync.js

Source: medic-injector-sync.js Github

copy
1/*
2 * This file is part of the Medic-Injector library.
3 *
4 * (c) Olivier Philippon <https://github.com/DrBenton>
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * Strongly inspired by the SwiftSuspenders (https://github.com/tschneidereit/SwiftSuspenders)
10 * ActionScript 3 library.
11 */
12
13(function(context) {
14
15    var myDebug = false;
16
17    /**
18     * @class InjectionMapping
19     */
20
21    var FORBIDDEN_INJECTIONS_NAMES = [
22        'injectionValue'
23    ];
24
25    /**
26     * You cant' use this constructor directly. Use Injector.addMapping to create a new "synchronous operations only"
27     * Injection Mapping.
28     *
29     * @class sync.InjectionMapping
30     * @constructor
31     * @param {sync.Injector} injectorInstance
32     * @param {String} injectionName
33     * @return {sync.InjectionMapping}
34     */
35    var InjectionMapping = function (injectorInstance, injectionName)
36    {
37        if (! (injectorInstance instanceof Injector)) {
38            throw new Error('Don\'t instantiate InjectionMapping directly ; use Injector#addMapping to create InjectionMappings!');
39        }
40        if (-1 < FORBIDDEN_INJECTIONS_NAMES.indexOf(injectionName)) {
41            throw new Error('Injection name "'+injectionName+'" is forbidden');
42        }
43        this._injector = injectorInstance;
44        /**
45         *
46         * @type {String}
47         */
48        this.injectionName = injectionName;
49    };
50
51    /**
52     * The simplest Injection Mapping type : each time a component will request this Injection Mapping injection, the
53     * target value will be injected.
54     * Since this value is a plain Javascript scalar, Array or Object, it's shared in all the application and calling
55     * #asSingleton on such an Injection Mapping is useless.
56     *
57     * @param value
58     * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
59     * @throws {Error}
60     */
61    InjectionMapping.prototype.toValue = function (value)
62    {
63        this._sealed && this._throwSealedException();
64        this._toValue = value;
65        return this;
66    };
67
68    /**
69     * The Injection Mapping value will be resolved through a Provider function.
70     *
71     * @param {Function} injectionValueProviderFunction
72     * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
73     * @throws {Error}
74     */
75    InjectionMapping.prototype.toProvider = function (injectionValueProviderFunction)
76    {
77        this._sealed && this._throwSealedException();
78        this._toProvider = injectionValueProviderFunction;
79        return this;
80    };
81
82    /**
83     * Each time this Injection Mapping value will be requested, a new instance of the target Javascript type will
84     * be created.
85     * Use it with #asSingleton() to map a lazy-loaded shared instance to this Injection Mapping.
86     *
87     * @param {Function} javascriptType
88     * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
89     * @throws {Error}
90     */
91    InjectionMapping.prototype.toType = function (javascriptType)
92    {
93        this._sealed && this._throwSealedException();
94        if (!(javascriptType instanceof Function))
95        {
96            throw new Error('InjectionMapping.toType() argument must be a Javascript type (i.e. a function instantiable with "new")')
97        }
98        this._toType = javascriptType;
99        return this;
100    };
101
102    /**
103     * When this method is called on an Injection Mapping, its resolution will be triggered the first time it is
104     * requested, but any subsequent call will use this first-time resolved value.
105     *
106     * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
107     * @throws {Error}
108     */
109    InjectionMapping.prototype.asSingleton = function ()
110    {
111        this._sealed && this._throwSealedException();
112        this._asSingleton = true;
113        return this;
114    };
115
116    /**
117     * Resolves the injection mapping.
118     *
119     * @return the Injection Mapping resolved value
120     */
121    InjectionMapping.prototype.resolveInjection = function ()
122    {
123        var returnedValue = null;
124
125        if (this._singletonValue) {
126
127            returnedValue = this._singletonValue;
128
129        } else if (this._toValue) {
130
131            returnedValue = this._toValue;
132
133        } else if (this._toType) {
134
135            returnedValue = new this._toType();
136
137        } else if (this._toProvider) {
138
139            // The Provider function may itself ask for other injections.
140            returnedValue = this._injector.triggerFunctionWithInjectedParams(this._toProvider);
141
142        }
143
144        if (this._asSingleton) {
145            this._singletonValue = returnedValue;//we won't ask for resolution again
146        }
147
148        return returnedValue;
149    };
150
151    /**
152     * Seal this Injection mapping. Any subsequent call to any of the
153     * #toValue, "toProvider()" or "asSingleton()" methods will throw
154     * an Error.
155     *
156     * @return {Object} returns a "unseal" key ; the only way to unseal this InjectionMapping it to call its "unseal()" method with this key
157     * @throws {Error}
158     * @see #unseal()
159     */
160    InjectionMapping.prototype.seal = function ()
161    {
162        this._sealed && this._throwSealedException();
163        this._sealed = true;
164        this._sealKey = {};
165        return this._sealKey;
166    };
167
168    /**
169     * Reverts the effect of <code>seal</code>, makes the mapping changeable again.
170     *
171     * @param {Object} key The key to unseal the mapping. Has to be the instance returned by
172     * <code>seal()</code>
173     * @return {sync.InjectionMapping} The <code>InjectionMapping</code> the method is invoked on
174     * @throws {Error} Has to be invoked with the unique key object returned by an earlier call to <code>seal</code>
175     * @throws {Error} Can't unseal a mapping that's not sealed
176     * @see #seal()
177     */
178    InjectionMapping.prototype.unseal = function (key)
179    {
180        if (!this._sealed) {
181            throw new Error('Can\'t unseal a non-sealed mapping.');
182        }
183        if (key !== this._sealKey)
184        {
185            throw new InjectorError('Can\'t unseal mapping without the correct key.');
186        }
187        this._sealed = false;
188        this._sealKey = null;
189        return this;
190    };
191
192    /**
193     * If the #seal method has been called on this InjectionMapping, returns `true`
194     * @return {Boolean}
195     */
196    InjectionMapping.prototype.isSealed = function ()
197    {
198        return this._sealed;
199    };
200
201    /**
202     *
203     * @private
204     */
205    InjectionMapping.prototype._throwSealedException = function ()
206    {
207        throw new Error('Modifications on a sealed InjectionMapping is forbidden!');
208    };
209
210    // Injector
211    /**
212     * Creates a new "synchronous operations only" Injector instance.
213     *
214     * Access this class with
215     * <code>var Injector = require('medic-injector').InjectorSync;</code>
216     *
217     * @class sync.Injector
218     * @constructor
219     * @return {sync.Injector}
220     */
221    var Injector = function ()
222    {
223        this._mappings = {};
224        return this;
225    };
226
227    /**
228     * The name of the function to trigger in a custom JS type instance after the resolution of all its Injections Points.
229     * @property {String}
230     */
231    Injector.prototype.instancePostInjectionsCallbackName = 'postInjections';
232
233    /**
234     * Adds a new InjectionMapping to the Injector.
235     *
236     * @param {String} injectionName
237     * @return {sync.InjectionMapping}
238     */
239    Injector.prototype.addMapping = function (injectionName)
240    {
241        if (!!this._mappings[injectionName]) {
242            throw new Error('Injection name "'+injectionName+'" is already used!');
243        }
244        var newInjectionMapping = new InjectionMapping(this, injectionName);
245        this._mappings[injectionName] = newInjectionMapping;
246        return newInjectionMapping;
247    };
248
249    /**
250     * Removes an existing InjectionMapping.
251     *
252     * @param {String} injectionName
253     * @return {sync.Injector}
254     * @throws {Error} An Error is thrown if the target InjectionMapping has been sealed
255     */
256    Injector.prototype.removeMapping = function (injectionName)
257    {
258        if (!!this._mappings[injectionName] && this._mappings[injectionName].isSealed()) {
259            throw new Error('Injection name "'+injectionName+'" is sealed and cannot be removed!');
260        }
261        delete this._mappings[injectionName];
262        return this;
263    };
264
265    /**
266     *
267     * @param {String} injectionName
268     * @return {Boolean}
269     */
270    Injector.prototype.hasMapping = function (injectionName)
271    {
272        return !!this._mappings[injectionName];
273    };
274
275    /**
276     *
277     * @param {String} injectionName
278     * @return {sync.InjectionMapping}
279     */
280    Injector.prototype.getMapping = function (injectionName)
281    {
282        return this._mappings[injectionName] || null;
283    };
284
285    /**
286     * Triggers the target function with the supplied context.
287     * The function args are parsed, and for each of these args whose name equals a registered InjectionMapping name
288     * the injection will be resolved and its value will fill the matching function arg value.
289     *
290     * @param {Function} func
291     * @param {Object} [context=null]
292     * @return the function returned value
293     */
294    Injector.prototype.triggerFunctionWithInjectedParams = function (func, context)
295    {
296        myDebug && console && console.log('triggerFunctionWithInjectedParams() ; func=', func);
297        var functionArgsNames = getArgumentNames(func);
298        var resolvedInjectionsValues = this.resolveInjections(functionArgsNames);
299        return func.apply(context, resolvedInjectionsValues);
300    };
301
302
303    /**
304     *
305     * @param {Object} jsTypeInstance
306     * @param {Boolean} [proceedToInjectionsInPostInjectionsMethodToo=false]
307     */
308    Injector.prototype.injectInto = function (jsTypeInstance, proceedToInjectionsInPostInjectionsMethodToo)
309    {
310        // Let's scan this JS object instance for injection points...
311        var propsToInject = [];
312        for (var propName in jsTypeInstance) {
313            if (null === jsTypeInstance[propName] && !!this._mappings[propName]) {
314                // This instance property is null and its name matches a registered injection name
315                // --> let's handle it as an injection point!
316                propsToInject.push(propName);
317            }
318        }
319
320        var resolvedInjectionsValues = this.resolveInjections(propsToInject);
321
322        for (var i = 0; i < resolvedInjectionsValues.length; i++) {
323            var propName = propsToInject[i]
324              , propValue = resolvedInjectionsValues[i];
325            jsTypeInstance[propName] = propValue;//property injection!
326        }
327
328        // Okay, now we may trigger the JS object instance "postInjection" method if it has one...
329        if (!!jsTypeInstance[this.instancePostInjectionsCallbackName] && (jsTypeInstance[this.instancePostInjectionsCallbackName] instanceof Function)) {
330            if (!proceedToInjectionsInPostInjectionsMethodToo) {
331                // Simple "postInjection" trigger
332                jsTypeInstance[this.instancePostInjectionsCallbackName].apply(jsTypeInstance);
333            } else {
334                // We will look for injections in the "postInjection" method too!
335                this.triggerFunctionWithInjectedParams(jsTypeInstance[this.instancePostInjectionsCallbackName], jsTypeInstance);
336            }
337        }
338    };
339
340    /**
341     *
342     * @param {Function} jsType
343     * @param {Boolean} [proceedToInjectionsInPostInjectionsMethodToo=false]
344     * @return a new instance of the given type, with its Injection Points resolved and its "post injections" callback triggered
345     */
346    Injector.prototype.createInjectedInstance = function (jsType, proceedToInjectionsInPostInjectionsMethodToo)
347    {
348        var newInstance = new jsType();
349        this.injectInto(newInstance, proceedToInjectionsInPostInjectionsMethodToo);
350        return newInstance;
351    };
352
353    /**
354     * Replaces all "${injectionName}" patterns in the given String with the values of the matching Injections Mappings.
355     * For each `null` injection mapping value, an empty string is used instead of 'null'.
356     *
357     * @param {String} str
358     * @return {String}
359     */
360    Injector.prototype.parseStr = function (str)
361    {
362        var requestedInjectionsNames = [];
363        str.replace(/\$\{([a-z0-9_]+)\}/ig, bind(function (fullStr, injectionName) {
364            if (!!this._mappings[injectionName]) {
365                requestedInjectionsNames.push(injectionName);
366            }
367            return fullStr;//don't replace anything for the moment...
368        }, this));
369
370
371        var resolvedInjectionsValues = this.resolveInjections(requestedInjectionsNames);
372        for (var i = 0; i < requestedInjectionsNames.length; i++) {
373            var injectionName = requestedInjectionsNames[i]
374              , injectionValue = (null === resolvedInjectionsValues[i]) ? '' : resolvedInjectionsValues[i] ;
375            str = str.replace('${' + injectionName + '}', injectionValue);
376        }
377
378        return str;
379    };
380
381    /**
382     * Set the value of all public properties of the target JS object whose name is an injection mapping to "null".
383     * This lets you cancel the effect of #injectInto for clean garbage collection.
384     *
385     * @param {Object} jsTypeInstance
386     */
387    Injector.prototype.cancelInjectionsInto = function (jsTypeInstance)
388    {
389        // Let's scan this JS object instance for injection points...
390        for (var propName in jsTypeInstance) {
391            if (!!this._mappings[propName]) {
392                // This instance property's name matches a registered injection name
393                // --> let's cancel this injection point
394                jsTypeInstance[propName] = null;
395            }
396        }
397    };
398
399    /**
400     *
401     * @param {Array} injectionsNamesArray an Array of Strings
402     * @return {Array} an Array of resolved Injections Mappings values
403     */
404    Injector.prototype.resolveInjections = function (injectionsNamesArray)
405    {
406        myDebug && console && console.log('resolveInjections() ; injectionsNamesArray=', injectionsNamesArray);
407        var resolvedInjectionPoints = [];
408
409        for (var i = 0; i < injectionsNamesArray.length; i++ ) {
410
411            var currentInjectionName = injectionsNamesArray[i];
412
413            if (!this._mappings[currentInjectionName]) {
414                // We have no mapping for this arg : we'll send `null` to the function for this arg
415                resolvedInjectionPoints.push(null);
416            } else {
417                // We resolve the mapping
418                resolvedInjectionPoints.push(this._mappings[currentInjectionName].resolveInjection());
419            }
420
421        }
422
423        return resolvedInjectionPoints;
424    };
425
426
427    // Library export
428
429    if (typeof exports !== 'undefined') {
430        if (typeof module !== 'undefined' && module.exports) {
431            exports = module.exports = Injector;
432        }
433        exports.MedicInjector = Injector;
434    } else if (typeof define === "function" && define.amd) {
435        define('medic-injector-sync', [], function () { return Injector; } );
436    } else {
437        context['MedicInjectorSync'] = Injector;
438    }
439
440
441    // Utils
442    // Function reflection
443    /**
444     * From Prototype library
445     * @see https://github.com/sstephenson/prototype/blob/master/src/prototype/lang/function.js
446     *
447     * Prototype JavaScript framework
448     * (c) 2005-2010 Sam Stephenson
449     *
450     * Prototype is freely distributable under the terms of an MIT-style license.
451     * For details, see the Prototype web site: http://www.prototypejs.org/
452     *
453     * @param {Function} fun
454     * @return {Array}
455     * @private
456     */
457    var getArgumentNames = function (fun)
458    {
459        var names = fun.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
460            .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
461            .replace(/\s+/g, '').split(',');
462        return names.length == 1 && !names[0] ? [] : names;
463    };
464
465    // Functions scope binding
466    /**
467     *
468     * @param {Function} func
469     * @param {Object} context
470     * @return {Function}
471     * @private
472     */
473    var bind = function (func, context)
474    {
475        var args = Array.prototype.slice.call(arguments, 2);
476        return function(){
477            return func.apply(context, args.concat(Array.prototype.slice.call(arguments)));
478        };
479    };
480
481
482})(this);
Full Screen

textFormatting.js

Source: textFormatting.js Github

copy
1////////////////////////////////////////////////////////////////////////////////
2//
3//	AT SOME POINT YOU NEED TO WEED ALL THIS DUPLICATED
4//	CAPABILITY OUT OF ENTITYINPUT.JS!
5//
6////////////////////////////////////////////////////////////////////////////////
7
8textFormatter = {
9
10	'formatString' : function (string, stripTags)
11	{
12		this.string = string;
13		this.stripTags = stripTags ? true : false;
14
15		this.chars = this.string.split('');
16		this.iPoints = new Array(this.chars.length);
17
18	//	this.chars.push('&nbsp;');
19		this.chars.push(' ');
20
21		// Remove potential html tag or entity characters
22		this.replaceChars('<', '&lt;');
23		this.replaceChars('>', '&gt;');
24		this.replaceChars('&', '&amp;');
25
26		// This makes it possible to see the caret and selection across new lines
27		this.replaceChars('\n', '&nbsp;\n');
28
29//		var isCommand = this.string[0] === '>';
30
31		this.renderText();
32
33		this.resolveInjections();
34
35		var displayString = this.chars.join('');
36
37		return displayString;
38	},
39
40	////////////////////////////////////////////////////////////////////////////////
41	//
42	//	SELECTIVE RENDER FUNCTIONS
43	//
44	////////////////////////////////////////////////////////////////////////////////
45
46	'renderText' : function ()
47	{
48		this.formatTag('r');
49		this.formatTag('g');
50		this.formatTag('b');
51		this.formatTag('c');
52		this.formatTag('y');
53		this.formatTag('m');
54		this.formatTag('rh');
55		this.formatTag('gh');
56		this.formatTag('bh');
57		this.formatTag('ch');
58		this.formatTag('yh');
59		this.formatTag('mh');
60		this.formatTag('ru');
61		this.formatTag('gu');
62		this.formatTag('bu');
63		this.formatTag('cu');
64		this.formatTag('yu');
65		this.formatTag('mu');
66
67		this.formatTag('rb');
68		this.formatTag('rbh');
69		this.formatTag('rbu');
70		this.formatTag('sv');
71	},
72
73	////////////////////////////////////////////////////////////////////////////////
74	//
75	//	PARSING & PRESENTATION FUNCTIONS
76	//
77	////////////////////////////////////////////////////////////////////////////////
78
79	'inject' : function (tag, index)
80	{
81		if (this.iPoints[index])
82		{
83			var otherTag = tag.opposite();
84			for (var i in this.iPoints[index])
85			{
86				if (otherTag.equals(this.iPoints[index][i]))
87				{
88					this.iPoints[index][i] = undefined;
89					return;
90				}
91			}
92		}
93		else
94		{
95			this.iPoints[index] = [];
96		}
97
98		if (tag.isOpenTag)
99		{
100			this.iPoints[index].push(tag);
101		}
102		else
103		{
104			this.iPoints[index].unshift(tag);
105		}
106
107	},
108
109	'resolveInjections' : function ()
110	{
111		var currentState = {
112			'order': []
113		};
114		var reps		= this.iPoints.length;
115		var openTags	= 0;
116
117		for (var stringIndex = 0; stringIndex <= reps; stringIndex++)
118		{
119			if (this.iPoints[stringIndex])
120			{
121				var currentTags = this.iPoints[stringIndex];
122
123				for (var currentTagIndex in currentTags)
124				{
125					var tag = currentTags[currentTagIndex];
126
127					if (!tag) continue;
128
129					if (tag.isOpenTag)
130					{
131						// We're opening a new tag.
132
133						if (currentState[tag.type] === undefined) currentState[tag.type] = 0;
134
135	//					var beforeState = Boolean(currentState[tag.type]);
136						currentState[tag.type]++;
137
138						currentState.order.push(tag.type);
139					}
140					else
141					{
142
143						// We're attempting to close a tag.
144
145						if (currentState[tag.type] === undefined || currentState[tag.type] < 1)
146						{
147	//						alert('Attempting to close tag that was never opened.');
148							continue;
149						}
150
151						currentState[tag.type]--;
152
153						var lastIndex = currentState.order.lastIndexOf(tag.type);
154
155						currentState.order.splice(lastIndex, 1);
156					}
157
158					// End of current tags
159				}
160
161				var tagString = ('</span>').repeat(openTags);
162
163				for (var i in currentState.order)
164				{
165					tagString = tagString + '<span class="' + currentState.order[i] + '">';
166				}
167				openTags = currentState.order.length;
168
169
170	//			this.iPoints[stringIndex] = '</span><span class = "' + currentState.order.join(' ') + '">';
171				this.iPoints[stringIndex] = tagString;
172
173			}
174		}
175
176		for (var stringIndex = reps; stringIndex >= 0; stringIndex--)
177		{
178			if (this.iPoints[stringIndex])
179			{
180				Array.prototype.splice.call(this.chars, stringIndex, 0, this.iPoints[stringIndex]);
181			}
182		}
183	},
184
185	'indexesOf' : function (string)
186	{
187		var index = undefined;
188		var indexes = [];
189
190		do
191		{
192			index = this.string.indexOf(string, index +1);
193			if (index !== -1) indexes.push(index);
194		}
195		while (index !== -1)
196
197		return indexes;
198	},
199
200	'replaceChars' : function (char, replacement)
201	{
202		var indexes = this.indexesOf(char);
203
204		for (var i in indexes)
205		{
206			this.chars[indexes[i]] = replacement;
207		}
208	},
209
210	'tagString' : function (string, tag)
211	{
212		var indexes = this.indexesOf(string);
213		var offset = string.length;
214
215		var open = new Tag(tag);
216		var close = new Tag('/' + tag);
217
218		for (var i in indexes)
219		{
220			this.inject(open, indexes[i]);
221			this.inject(close, indexes[i] + offset);
222		}
223	},
224
225	'removeString' : function (string)
226	{
227		var indexes = this.indexesOf(string);
228		var offset = string.length;
229
230		for (var i in indexes)
231		{
232			for (var j = 0; j < offset; j++)
233			{
234				this.chars[indexes[i] + j] = '';
235			}
236		}
237	},
238
239	'injectBefore' : function (string, tag)
240	{
241		var indexes = this.indexesOf(string);
242
243		var iTag = new Tag(tag);
244
245		for (var i in indexes)
246		{
247			this.inject(iTag, indexes[i]);
248		}
249	},
250
251	'injectAfter' : function (string, tag)
252	{
253		var indexes = this.indexesOf(string);
254		var offset = string.length;
255		var iTag = new Tag(tag);
256
257		for (var i in indexes)
258		{
259			this.inject(iTag, indexes[i] + offset);
260		}
261	},
262
263	'formatTag' : function (tag)
264	{
265		this.injectAfter('[' + tag + ']', tag);
266		this.injectBefore('[/' + tag + ']', '/' + tag);
267
268		if (this.stripTags)
269		{
270			this.removeString('[' + tag + ']');
271			this.removeString('[/' + tag + ']');
272		}
273		else
274		{
275			this.tagString('[' + tag + ']', 'k');
276			this.tagString('[/' + tag + ']', 'k');
277		}
278	}
279};
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)