How to use formatInstance method in Playwright Internal

Best JavaScript code snippet using playwright-internal

angular-selectbox.js

Source:angular-selectbox.js Github

copy

Full Screen

...11 $templateCache.put('selectbox.html',12 '<div ' +13 ' tabindex="{{ vm.instance }}" ' +14 ' class="sb-container" ' +15 ' id="{{ vm.formatInstance(vm.instance) }}">' +16 ' <a href="" ' +17 ' class="sb-toggle" ' +18 ' ng-click="vm.toggle()" ' +19 ' ng-class="{\'sb-toggle-active\': vm.active}">' +20 ' {{ vm.selected[vm.labelKey] || vm.value || \'Select\' }}' +21 ' </a>' +22 ' <ul class="sb-dropdown" ng-show="vm.active">' +23 ' <li ' +24 ' class="sb-item" ' +25 ' ng-repeat="option in vm.options track by $index" ' +26 ' ng-class="{\'sb-item-active\': option === vm.selected,\'sb-item-focus\': $index === vm.focus}">' +27 ' <a href="" ' +28 ' class="sb-item-handle" ' +29 ' ng-click="vm.change(option)" ' +30 ' title="{{ option[vm.labelKey] || option }}">' +31 ' {{ option[vm.labelKey] || option }}' +32 ' </a>' +33 ' </li>' +34 ' <li class="sb-item sb-empty" ng-if="vm.options.length === 0">the list is empty</li>' +35 ' </ul>' +36 '</div>');37 $templateCache.put('selectbox-multi.html',38 '<div ' +39 ' tabindex="{{ vm.instance }}" ' +40 ' class="sb-container sb-container-multi" ' +41 ' id="{{ vm.formatInstance(vm.instance) }}">' +42 ' <a href="" ' +43 ' class="sb-toggle" ' +44 ' ng-click="vm.toggle()" ' +45 ' ng-class="{\'sb-toggle-active\': vm.active}">' +46 ' {{ vm.title }}{{ vm.values.length ? (\': \' + vm.values.length) : \'\' }}' +47 ' </a>' +48 ' <ul class="sb-dropdown" ng-show="vm.active">' +49 ' <li ' +50 ' class="sb-item" ' +51 ' ng-repeat="option in vm.options track by $index" ' +52 ' ng-class="{\'sb-item-active\': vm.contains(vm.values, option[vm.idKey]),\'sb-item-focus\': $index === vm.focus}">' +53 ' <a href="" ' +54 ' class="sb-item-handle" ' +55 ' ng-click="vm.change(option)" ' +56 ' title="{{ option[vm.labelKey] || option }}">' +57 ' {{ option[vm.labelKey] || option }}' +58 ' </a>' +59 ' </li>' +60 ' <li class="sb-item sb-empty" ng-if="vm.options.length === 0">the list is empty</li>' +61 ' </ul>' +62 '</div>');63 }64 /** @ngInject */65 function selectbox() {66 return {67 restrict: 'E',68 templateUrl: 'selectbox.html',69 scope: {},70 controller: SelectboxController,71 controllerAs: 'vm',72 bindToController: {73 options: '=',74 value: '=',75 idKey: '@',76 labelKey: '@',77 onChange: '&'78 }79 };80 /** @ngInject */81 function SelectboxController($scope, $element, $document, $timeout, Selectbox) {82 var vm = this;83 var _sbDropdown = $element[0].querySelector('.sb-dropdown');84 var _defaults = Selectbox.getDefaults();85 vm.instance = Selectbox.getInstance();86 vm.active = _defaults.active;87 vm.focus = _defaults.focus;88 vm.idKey = vm.idKey || _defaults.idKey;89 vm.labelKey = vm.labelKey || _defaults.labelKey;90 _getSelected();91 vm.formatInstance = formatInstance;92 vm.toggle = toggle;93 vm.change = change;94 $scope.$on('$destroy', _unbind);95 /**96 * Get selected object97 *98 * @private99 */100 function _getSelected() {101 if (!vm.options.length) { return; }102 if (vm.options[0][vm.idKey]) {103 for (var i = 0; i < vm.options.length; i += 1) {104 if (vm.options[i][vm.idKey] === vm.value) {105 vm.selected = vm.options[i];106 break;107 }108 }109 } else {110 vm.selected = vm.value;111 }112 }113 /**114 * Format instance identifier to be used in the view as id for example115 *116 * @returns {string} formatted instance identifier117 */118 function formatInstance() {119 return Selectbox.formatInstance(vm.instance);120 }121 /**122 * Toggle drop-down visibility and (un)bind events123 *124 */125 function toggle() {126 vm.active = !vm.active;127 $timeout(function () {128 if (vm.active) {129 _bind();130 } else {131 _unbind();132 }133 });134 }135 /**136 * Change selected value and initiate the callback function if defined137 *138 * @param {*} value value to select139 */140 function change(value) {141 vm.value = value[vm.idKey] || value;142 _getSelected();143 if (angular.isDefined(vm.onChange)) { vm.onChange({value: vm.value}); }144 }145 /**146 * Handle click event on document in order to determine147 * if selectbox should be closed148 *149 * @param {Object} e event object150 * @private151 */152 function _handleClick(e) {153 var targetId = Selectbox.getId(e.target.parentNode);154 if (formatInstance() === targetId) { return; }155 toggle();156 }157 /**158 * Handle keydown event159 * - recognize ENTER in order to select value160 * - recognize UP and DOWN arrow keys to highlight the value161 *162 * @param {Object} e event object163 * @param {number} e.keyCode event key code164 * @private165 */166 function _handleKeyDown(e) {167 var min = 0;168 var max = vm.options.length - 1;169 if (e.keyCode === 13) { // enter170 $timeout(function () {171 vm.change(vm.options[vm.focus]);172 });173 return;174 }175 if (e.keyCode !== 40 && e.keyCode !== 38) { return; }176 $timeout(function () {177 vm.focus = Selectbox.getFocus(vm.focus, min, max, e.keyCode);178 Selectbox.updateScrollPosition(vm.focus, _sbDropdown);179 });180 }181 /**182 * Bind click and keydown events183 *184 * @private185 */186 function _bind() {187 $document.bind('click', _handleClick);188 $element.on('keydown', _handleKeyDown);189 }190 /**191 * Unbind click and keydown events and reset focus192 *193 * @private194 */195 function _unbind() {196 vm.focus = 0;197 $document.unbind('click', _handleClick);198 $element.off('keydown', _handleKeyDown);199 }200 }201 }202 function selectboxMulti() {203 return {204 restrict: 'E',205 templateUrl: 'selectbox-multi.html',206 scope: {},207 controller: SelectboxMultiController,208 controllerAs: 'vm',209 bindToController: {210 title: '@',211 options: '=',212 values: '=',213 idKey: '@',214 labelKey: '@',215 onChange: '&'216 }217 };218 /** @ngInject */219 function SelectboxMultiController($scope, $element, $document, $timeout, Selectbox) {220 var vm = this;221 var _sbDropdown = $element[0].querySelector('.sb-dropdown');222 var _defaults = Selectbox.getDefaults();223 vm.instance = Selectbox.getInstance();224 vm.title = vm.title || 'Select';225 vm.active = _defaults.active;226 vm.focus = _defaults.focus;227 vm.idKey = vm.idKey || _defaults.idKey;228 vm.labelKey = vm.labelKey || _defaults.labelKey;229 vm.formatInstance = formatInstance;230 vm.toggle = toggle;231 vm.change = change;232 vm.contains = contains;233 $scope.$on('$destroy', _unbind);234 /**235 * Format instance identifier to be used in the view as id for example236 *237 * @returns {string} formatted instance identifier238 */239 function formatInstance() {240 return Selectbox.formatInstance(vm.instance);241 }242 /**243 * Toggle drop-down visibility and (un)bind events244 *245 */246 function toggle() {247 vm.active = !vm.active;248 $timeout(function () {249 if (vm.active) {250 _bind();251 } else {252 _unbind();253 }254 });255 }256 /**257 * Change selected values and initiate the callback function if defined258 *259 * @param {*} value value to select260 */261 function change(value) {262 var id = value[vm.idKey];263 var index = vm.values.indexOf(id);264 if (index === -1) {265 vm.values.push(id);266 } else {267 vm.values.splice(index, 1);268 }269 if (angular.isDefined(vm.onChange)) { vm.onChange({values: vm.values}); }270 }271 /**272 * Check if item belongs to an array273 *274 * @param {Array} array array where the item is checked275 * @param {*} item item which is checked276 * @returns {boolean}277 */278 function contains(array, item) {279 return array.indexOf(item) !== -1;280 }281 /**282 * Handle click event on document in order to determine283 * if selectbox should be closed284 *285 * @param {Object} e event object286 * @private287 */288 function _handleClick(e) {289 var targetId = Selectbox.getId(e.target.parentNode);290 var itemClicked = !targetId && e.target.classList.contains('sb-item-handle');291 if (formatInstance() === targetId || itemClicked) { return; }292 toggle();293 }294 /**295 * Handle keydown event296 * - recognize SPACE in order to select values297 * - recognize ENTER in order to close dropdown298 * - recognize UP and DOWN arrow keys to highlight the value299 *300 * @param {Object} e event object301 * @param {number} e.keyCode event key code302 * @private303 */304 function _handleKeyDown(e) {305 var min = 0;306 var max = vm.options.length - 1;307 if ([32, 13].indexOf(e.keyCode) !== -1) { // space or enter308 $timeout(function () {309 if (e.keyCode === 13) { // enter310 _unbind();311 }312 if (e.keyCode === 32) { // space313 vm.change(vm.options[vm.focus]);314 }315 });316 return;317 }318 if (e.keyCode !== 40 && e.keyCode !== 38) { return; }319 $timeout(function () {320 vm.focus = Selectbox.getFocus(vm.focus, min, max, e.keyCode);321 Selectbox.updateScrollPosition(vm.focus, _sbDropdown);322 });323 }324 /**325 * Bind click and keydown events326 *327 * @private328 */329 function _bind() {330 $document.bind('click', _handleClick);331 $element.on('keydown', _handleKeyDown);332 }333 /**334 * Unbind click and keydown events and reset focus335 *336 * @private337 */338 function _unbind() {339 vm.focus = _defaults.focus;340 vm.active = _defaults.active;341 $document.unbind('click', _handleClick);342 $element.off('keydown', _handleKeyDown);343 }344 }345 }346 function Selectbox() {347 var _counter = 0;348 var _defaults = {349 active: false,350 focus: 0,351 idKey: 'id',352 labelKey: 'label'353 };354 return {355 getInstance: getInstance,356 getDefaults: getDefaults,357 formatInstance: formatInstance,358 getFocus: getFocus,359 updateScrollPosition: updateScrollPosition,360 getId: getId361 };362 /**363 * Get next instance identifier364 *365 * @returns {number}366 */367 function getInstance() {368 _counter += 1;369 return _counter;370 }371 /**372 * Get default options373 *374 * @returns {*}375 */376 function getDefaults() {377 return angular.copy(_defaults);378 }379 /**380 * Format instance in order to use it in template381 *382 * @param {number} instance instance identifier383 * @returns {string}384 */385 function formatInstance(instance) {386 return 'sb-' + instance;387 }388 /**389 * Update focus of the element390 *391 * @param {number} focus current focus392 * @param {number} min minimal focus393 * @param {number} max maximum focus394 * @param {number} keyCode keycode which tell if going up or down395 * @returns {*}396 */397 function getFocus(focus, min, max, keyCode) {398 if (keyCode === 40) { // key arrow down399 focus = (focus >= max) ? min : (focus + 1);...

Full Screen

Full Screen

jquery.liblink.js

Source:jquery.liblink.js Github

copy

Full Screen

1/*jslint browser: true */2/*jslint white: true */3(function( $ ){4 'use strict';5// Helpers6 // Test in an object is an instance of jQuery or Zepto.7 function isInstance ( a ) {8 return a instanceof $ || ( $.zepto && $.zepto.isZ(a) );9 }10// Link types11 function fromPrefix ( target, method ) {12 // If target is a string, a new hidden input will be created.13 if ( typeof target === 'string' && target.indexOf('-inline-') === 0 ) {14 // By default, use the 'html' method.15 this.method = method || 'html';16 // Use jQuery to create the element17 this.target = this.el = $( target.replace('-inline-', '') || '<div/>' );18 return true;19 }20 }21 function fromString ( target ) {22 // If the string doesn't begin with '-', which is reserved, add a new hidden input.23 if ( typeof target === 'string' && target.indexOf('-') !== 0 ) {24 this.method = 'val';25 var element = document.createElement('input');26 element.name = target;27 element.type = 'hidden';28 this.target = this.el = $(element);29 return true;30 }31 }32 function fromFunction ( target ) {33 // The target can also be a function, which will be called.34 if ( typeof target === 'function' ) {35 this.target = false;36 this.method = target;37 return true;38 }39 }40 function fromInstance ( target, method ) {41 if ( isInstance( target ) && !method ) {42 // If a jQuery/Zepto input element is provided, but no method is set,43 // the element can assume it needs to respond to 'change'...44 if ( target.is('input, select, textarea') ) {45 // Default to .val if this is an input element.46 this.method = 'val';47 // Fire the API changehandler when the target changes.48 this.target = target.on('change.liblink', this.changeHandler);49 } else {50 this.target = target;51 // If no method is set, and we are not auto-binding an input, default to 'html'.52 this.method = 'html';53 }54 return true;55 }56 }57 function fromInstanceMethod ( target, method ) {58 // The method must exist on the element.59 if ( isInstance( target ) &&60 (typeof method === 'function' ||61 (typeof method === 'string' && target[method]))62 ) {63 this.method = method;64 this.target = target;65 return true;66 }67 }68var69/** @const */70 creationFunctions = [fromPrefix, fromString, fromFunction, fromInstance, fromInstanceMethod];71// Link Instance72/** @constructor */73 function Link ( target, method, format ) {74 var that = this, valid = false;75 // Forward calls within scope.76 this.changeHandler = function ( changeEvent ) {77 var decodedValue = that.formatInstance.from( $(this).val() );78 // If the value is invalid, stop this event, as well as it's propagation.79 if ( decodedValue === false || isNaN(decodedValue) ) {80 // Reset the value.81 $(this).val(that.lastSetValue);82 return false;83 }84 that.changeHandlerMethod.call( '', changeEvent, decodedValue );85 };86 // See if this Link needs individual targets based on its usage.87 // If so, return the element that needs to be copied by the88 // implementing interface.89 // Default the element to false.90 this.el = false;91 // Store the formatter, or use the default.92 this.formatInstance = format;93 // Try all Link types.94 /*jslint unparam: true*/95 $.each(creationFunctions, function(i, fn){96 valid = fn.call(that, target, method);97 return !valid;98 });99 /*jslint unparam: false*/100 // Nothing matched, throw error.101 if ( !valid ) {102 throw new RangeError("(Link) Invalid Link.");103 }104 }105 // Provides external items with the object value.106 Link.prototype.set = function ( value ) {107 // Ignore the value, so only the passed-on arguments remain.108 var args = Array.prototype.slice.call( arguments ),109 additionalArgs = args.slice(1);110 // Store some values. The actual, numerical value,111 // the formatted value and the parameters for use in 'resetValue'.112 // Slice additionalArgs to break the relation.113 this.lastSetValue = this.formatInstance.to( value );114 // Prepend the value to the function arguments.115 additionalArgs.unshift(116 this.lastSetValue117 );118 // When target is undefined, the target was a function.119 // In that case, provided the object as the calling scope.120 // Branch between writing to a function or an object.121 ( typeof this.method === 'function' ?122 this.method :123 this.target[ this.method ] ).apply( this.target, additionalArgs );124 };125// Developer API126/** @constructor */127 function LinkAPI ( origin ) {128 this.items = [];129 this.elements = [];130 this.origin = origin;131 }132 LinkAPI.prototype.push = function( item, element ) {133 this.items.push(item);134 // Prevent 'false' elements135 if ( element ) {136 this.elements.push(element);137 }138 };139 LinkAPI.prototype.reconfirm = function ( flag ) {140 var i;141 for ( i = 0; i < this.elements.length; i += 1 ) {142 this.origin.LinkConfirm(flag, this.elements[i]);143 }144 };145 LinkAPI.prototype.remove = function ( flag ) {146 var i;147 for ( i = 0; i < this.items.length; i += 1 ) {148 this.items[i].target.off('.liblink');149 }150 for ( i = 0; i < this.elements.length; i += 1 ) {151 this.elements[i].remove();152 }153 };154 LinkAPI.prototype.change = function ( value ) {155 if ( this.origin.LinkIsEmitting ) {156 return false;157 }158 this.origin.LinkIsEmitting = true;159 var args = Array.prototype.slice.call( arguments, 1 ), i;160 args.unshift( value );161 // Write values to serialization Links.162 // Convert the value to the correct relative representation.163 for ( i = 0; i < this.items.length; i += 1 ) {164 this.items[i].set.apply(this.items[i], args);165 }166 this.origin.LinkIsEmitting = false;167 };168// jQuery plugin169 function binder ( flag, target, method, format ){170 if ( flag === 0 ) {171 flag = this.LinkDefaultFlag;172 }173 // Create a list of API's (if it didn't exist yet);174 if ( !this.linkAPI ) {175 this.linkAPI = {};176 }177 // Add an API point.178 if ( !this.linkAPI[flag] ) {179 this.linkAPI[flag] = new LinkAPI(this);180 }181 var linkInstance = new Link ( target, method, format || this.LinkDefaultFormatter );182 // Default the calling scope to the linked object.183 if ( !linkInstance.target ) {184 linkInstance.target = $(this);185 }186 // If the Link requires creation of a new element,187 // Pass the element and request confirmation to get the changehandler.188 // Set the method to be called when a Link changes.189 linkInstance.changeHandlerMethod = this.LinkConfirm( flag, linkInstance.el );190 // Store the linkInstance in the flagged list.191 this.linkAPI[flag].push( linkInstance, linkInstance.el );192 // Now that Link have been connected, request an update.193 this.LinkUpdate( flag );194 }195 /** @export */196 $.fn.Link = function( flag ){197 var that = this;198 // Delete all linkAPI199 if ( flag === false ) {200 return that.each(function(){201 // .Link(false) can be called on elements without Links.202 // When that happens, the objects can't be looped.203 if ( !this.linkAPI ) {204 return;205 }206 $.map(this.linkAPI, function(api){207 api.remove();208 });209 delete this.linkAPI;210 });211 }212 if ( flag === undefined ) {213 flag = 0;214 } else if ( typeof flag !== 'string') {215 throw new Error("Flag must be string.");216 }217 return {218 to: function( a, b, c ){219 return that.each(function(){220 binder.call(this, flag, a, b, c);221 });222 }223 };224 };...

Full Screen

Full Screen

wegas-bscopeinspector.js

Source:wegas-bscopeinspector.js Github

copy

Full Screen

...39 },40 formatInstance: function(instance, mine) {41 if (instance) {42 if (instance === mine) {43 return "<b>↬" + this.formatInstance(instance, null) + "</b>";44 } else {45 this.count++;46 return "✓" + instance.get("value");47 }48 }49 return "✗";50 },51 instanceUpdateTrigger: function(e) {52 var theVar = this.get("variable.evaluated");53 e.entity;54 this.syncUI();55 },56 syncUI: function() {57 var theVar = this.get("variable.evaluated"), i, j,58 mine = theVar.getInstance(),59 theUl = this.get(CONTENTBOX).one("ul"),60 instances = Y.Wegas.Facade.Instance.cache.find("descriptorId", theVar.get("id")).variableInstances,61 game = Y.Wegas.Facade.Game.cache.getCurrentGame(),62 team, player,63 output = "";64 this.count = 0;65 output += "<li>Global: " + this.formatInstance(instances[0], mine) + "</li>";66 output += "<ul>";67 for (i in game.get("teams")) {68 team = game.get("teams")[i];69 output += "<li>Team: " + this.formatInstance(instances[team.get("id")], mine) + "</li>";70 output += "<ul>";71 for (j in team.get("players")) {72 player = team.get("players")[j];73 output += "<li>Player: " + this.formatInstance(instances[player.get("id")], mine) + "</li>";74 }75 output += "</ul>";76 }77 output += "</ul>";78 output += this.count + " / " + Object.keys(instances).length;79 theUl.setHTML(output);80 },81 destructor: function() {82 var i;83 for (i = 0; i < this.handlers.length; i += 1) {84 this.handlers[i].detach();85 }86 }87 }, {...

Full Screen

Full Screen

lightning_internationalizationLibrary_datetime_intlFormat.js

Source:lightning_internationalizationLibrary_datetime_intlFormat.js Github

copy

Full Screen

1import locale from '/1/module/esm/0/l/en-US/mi/@salesforce/i18n/locale/v/1_14_4-alpha/latest/@salesforce_i18n_locale.js';2import { DateTimeOptions } from '/1/module/esm/0/l/en-US/mi/lightning/internationalizationLibrary#datetime/dateTimeOptions/v/1_14_4-alpha/latest/lightning_internationalizationLibrary_datetime_dateTimeOptions.js';3import { formatDateUTC, formatDate, toOtherCalendar, syncUTCToWallTime } from '/1/module/esm/0/l/en-US/mi/lightning/internationalizationLibrary#localizationService/v/1_14_4-alpha/latest/lightning_internationalizationLibrary_localizationService.js';4import { isValidISODateTimeString, TIME_SEPARATOR } from '/1/module/esm/0/l/en-US/mi/lightning/iso8601Utils/v/1_14_4-alpha/latest/lightning_iso8601Utils.js';5const dateTimeFormatInstancesCache = {};6const POSSIBLE_OPTS = {7 weekday: true,8 era: true,9 year: true,10 month: true,11 day: true,12 hour: true,13 minute: true,14 second: true,15 timeZone: true,16 timeZoneName: true,17 hour12: true18};19function getOptionsUniqueKey(options) {20 return Object.keys(options).sort().reduce((prev, optionName) => {21 if (POSSIBLE_OPTS[optionName]) {22 return prev + optionName + options[optionName] + '';23 }24 return prev;25 }, '');26}27function getFromCache(options) {28 const optionsUniqueKey = getOptionsUniqueKey(options);29 let formatInstance = dateTimeFormatInstancesCache[optionsUniqueKey];30 if (!formatInstance) {31 formatInstance = new Intl.DateTimeFormat(locale, options);32 dateTimeFormatInstancesCache[optionsUniqueKey] = formatInstance;33 }34 return formatInstance;35}36function convertAndFormatDate(date, format, timeZone) {37 const translatedDate = toOtherCalendar(date);38 const converted = syncUTCToWallTime(translatedDate, timeZone);39 return formatDateUTC(converted, format);40}41function isDate(value) {42 return Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value.getTime());43}44function toDate(value) {45 let dateObj = value;46 if (!isDate(value) && (typeof value === 'string' || typeof value === 'number')) {47 dateObj = new Date(isFinite(value) ? parseInt(value, 10) : Date.parse(value));48 }49 return dateObj;50}51const isTimeZonesSupported = function () {52 try {53 // IE11 only supports the UTC time zone and throws when given anything else54 // eslint-disable-next-line new-cap55 Intl.DateTimeFormat('en-US', {56 timeZone: 'America/Los_Angeles'57 });58 } catch (err) {59 return false;60 }61 return true;62}();63function dateTimeFormatFallback(dto) {64 // localization service will default to mediumDateFormat when no format is provided65 const format = dto.hasFormattingOptions() ? dto.getSkeleton() : null;66 const {67 timeZone68 } = dto.options;69 return {70 format: value => {71 // if value is an ISO date string (e.g. 2019-10-25), do not convert between timezones and just format the date72 if (isValidISODateTimeString(value) && value.indexOf(TIME_SEPARATOR) < 0) {73 return formatDate(value);74 } // FIXME use standard methods from localizationService for parsing and formatting instead75 const dateObj = toDate(value);76 if (isDate(dateObj)) {77 if (timeZone === 'UTC') {78 dateObj.setTime(dateObj.getTime() + dateObj.getTimezoneOffset() * 60 * 1000);79 }80 return convertAndFormatDate(dateObj, format, timeZone);81 }82 return '';83 }84 };85}86export function dateTimeFormat(opts) {87 const options = opts || {};88 const dto = new DateTimeOptions(options);89 if (!('Intl' in window) || !dto.hasFormattingOptions() || !isTimeZonesSupported) {90 return dateTimeFormatFallback(dto);91 }92 return {93 format: value => {94 const dtf = getFromCache(options);95 return dtf.format(toDate(value));96 }97 };...

Full Screen

Full Screen

intlFormat.js

Source:intlFormat.js Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6 */7import { DateTimeOptions } from './dateTimeOptions';8import {9 formatDateUTC,10 formatDate,11 toOtherCalendar,12 syncUTCToWallTime13} from '../localizationService';14import { isValidISODateTimeString, TIME_SEPARATOR } from 'c/iso8601Utils';15const locale = 'en-US';16const dateTimeFormatInstancesCache = {};17const POSSIBLE_OPTS = {18 weekday: true,19 era: true,20 year: true,21 month: true,22 day: true,23 hour: true,24 minute: true,25 second: true,26 timeZone: true,27 timeZoneName: true,28 hour12: true29};30function getOptionsUniqueKey(options) {31 return Object.keys(options)32 .sort()33 .reduce((prev, optionName) => {34 if (POSSIBLE_OPTS[optionName]) {35 return prev + optionName + options[optionName] + '';36 }37 return prev;38 }, '');39}40function getFromCache(options) {41 const optionsUniqueKey = getOptionsUniqueKey(options);42 let formatInstance = dateTimeFormatInstancesCache[optionsUniqueKey];43 if (!formatInstance) {44 formatInstance = new Intl.DateTimeFormat(locale, options);45 dateTimeFormatInstancesCache[optionsUniqueKey] = formatInstance;46 }47 return formatInstance;48}49function convertAndFormatDate(date, format, timeZone) {50 const translatedDate = toOtherCalendar(date);51 const converted = syncUTCToWallTime(translatedDate, timeZone);52 return formatDateUTC(converted, format);53}54function isDate(value) {55 return (56 Object.prototype.toString.call(value) === '[object Date]' &&57 !isNaN(value.getTime())58 );59}60function toDate(value) {61 let dateObj = value;62 if (63 !isDate(value) &&64 (typeof value === 'string' || typeof value === 'number')65 ) {66 dateObj = new Date(67 isFinite(value) ? parseInt(value, 10) : Date.parse(value)68 );69 }70 return dateObj;71}72const isTimeZonesSupported = (function () {73 try {74 // eslint-disable-next-line new-cap75 Intl.DateTimeFormat('en-US', { timeZone: 'America/Los_Angeles' });76 } catch (err) {77 return false;78 }79 return true;80})();81function dateTimeFormatFallback(dto) {82 const format = dto.hasFormattingOptions() ? dto.getSkeleton() : null;83 const { timeZone } = dto.options;84 return {85 format: (value) => {86 if (87 isValidISODateTimeString(value) &&88 value.indexOf(TIME_SEPARATOR) < 089 ) {90 return formatDate(value);91 }92 const dateObj = toDate(value);93 if (isDate(dateObj)) {94 if (timeZone === 'UTC') {95 dateObj.setTime(96 dateObj.getTime() +97 dateObj.getTimezoneOffset() * 60 * 100098 );99 }100 return convertAndFormatDate(dateObj, format, timeZone);101 }102 return '';103 }104 };105}106export function dateTimeFormat(opts) {107 const options = opts || {};108 const dto = new DateTimeOptions(options);109 if (110 !('Intl' in window) ||111 !dto.hasFormattingOptions() ||112 !isTimeZonesSupported113 ) {114 return dateTimeFormatFallback(dto);115 }116 return {117 format: (value) => {118 const dtf = getFromCache(options);119 return dtf.format(toDate(value));120 }121 };...

Full Screen

Full Screen

rud.js

Source:rud.js Github

copy

Full Screen

...16 if (groups[inst.instanceGroupId] == null) {17 groups[inst.instanceGroupId] = await InstanceGroup.findById(inst.instanceGroupId).lean();18 groups[inst.instanceGroupId].instances = [];19 }20 inst = await formatInstance(inst);21 groups[inst.instanceGroupId].instances.push(inst);22 }23 let result = { instance_groups: [] };24 Object.keys(groups).forEach(group => result.instance_groups.push(groups[group]));25 res.json(result);26 })27 .catch(err => ErrorHandler.processError(err, res));28});29router.get('/:id', (req, res) => {30 Authentication.verifyUserToken(req.headers.auth_token)31 .then((user) => Instance.findOne({_id: req.params.id, userId: user._id}).lean())32 .then(async inst => {33 if (inst == null){34 return ErrorHandler.errorCustomMessage("Instance not found or doesn't belong to user", res);35 }36 inst = await formatInstance(inst);37 res.json(inst);38 })39 .catch(err => ErrorHandler.processError(err, res));40});41async function formatInstance(inst){42 if (inst.portRangeStart) {43 inst.assignedPortRange = inst.portRangeStart + ' - ' + (inst.portRangeStart + 100);44 delete inst.portRangeStart;45 }46 let physicalMachine = await PhysicalMachine.findById(inst.physicalMachineId).lean();47 inst.physicalMachine = physicalMachine;48 delete inst.physicalMachineId;49 if (physicalMachine) {50 inst.ipAddress = await IpAddress.findById(physicalMachine.ipAddressId).lean();51 }52 delete inst.ipAddressId;53 return inst;54}55module.exports = router;

Full Screen

Full Screen

all_6.js

Source:all_6.js Github

copy

Full Screen

1var searchData=2[3 ['file_0',['file',['../structcallInfo.html#a25ca0b94ea2d104559bdc65c70c2f89f',1,'callInfo']]],4 ['firsth_1',['FIRSTH',['../stack_8cpp.html#a8f2d9af05b9e8b17d5657db338c2705f',1,'stack.cpp']]],5 ['formatinstance_2',['formatInstance',['../stack_8h.html#ac258f0fde27f7e5c0485497517a1ac16',1,'formatInstance(const elem_t *instance):&#160;stack.cpp'],['../stack_8cpp.html#ac258f0fde27f7e5c0485497517a1ac16',1,'formatInstance(const elem_t *instance):&#160;stack.cpp']]],6 ['funcname_3',['funcName',['../structcallInfo.html#ad203a4df48aa5ec7f60dd234a20d3346',1,'callInfo']]]...

Full Screen

Full Screen

functions_1.js

Source:functions_1.js Github

copy

Full Screen

1var searchData=2[3 ['formatinstance_0',['formatInstance',['../stack_8h.html#ac258f0fde27f7e5c0485497517a1ac16',1,'formatInstance(const elem_t *instance):&#160;stack.cpp'],['../stack_8cpp.html#ac258f0fde27f7e5c0485497517a1ac16',1,'formatInstance(const elem_t *instance):&#160;stack.cpp']]]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright/lib/server/inspector');2const { Page } = require('playwright/lib/server/page');3const { BrowserContext } = require('playwright/lib/server/browserContext');4const { Browser } = require('playwright/lib/server/browser');5const { BrowserType } = require('playwright/lib/server/browserType');6const { Playwright } = require('playwright/lib/server/playwright');7const playwright = new Playwright();8const browserType = new BrowserType(playwright, 'chromium');9const browser = new Browser(browserType, 'browser-1', 'chromium');10const context = new BrowserContext(browser, 'context-1');11const page = new Page(context, 'page-1');12console.log(formatInstance(page));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright/lib/client/helper');2const { formatOptions } = require('playwright/lib/client/helper');3const { formatError } = require('playwright/lib/client/helper');4const { formatResult } = require('playwright/lib/client/helper');5const { formatSuccess } = require('playwright/lib/client/helper');6const { formatMessage } = require('playwright/lib/client/helper');7const { chromium } = require('playwright');8(async () => {9 const browser = await chromium.launch();10 const page = await browser.newPage();11 await page.screenshot({ path: `example.png` });12 await browser.close();13})();14const { formatMessage } = require('playwright/lib/client/helper');15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const page = await browser.newPage();19 await page.screenshot({ path: `example.png` });20 await browser.close();21})();22const { formatInstance } = require('playwright/lib/client/helper');23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const page = await browser.newPage();27 await page.screenshot({ path: `example.png` });28 await browser.close();29})();30const { formatOptions } = require('playwright/lib/client/helper');31const { chromium } = require('playwright');32(async () => {33 const browser = await chromium.launch();34 const page = await browser.newPage();35 await page.screenshot({ path: `example.png` });36 await browser.close();37})();38const { formatError } = require('playwright

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright/lib/server/common/inspectorSocket');2const { Page } = require('playwright/lib/server/chromium/crPage');3const { Frame } = require('playwright/lib/server/chromium/crFrame');4const { ElementHandle } = require('playwright/lib/server/chromium/crElementHandle');5const { JSHandle } = require('playwright/lib/server/chromium/crJSHandle');6const { ExecutionContext } = require('playwright/lib/server/chromium/crExecutionContext');7const page = new Page();8const frame = new Frame(page, 'frameId');9const elementHandle = new ElementHandle(frame, 'elementHandleId');10const jsHandle = new JSHandle(elementHandle, 'jsHandleId', 'object');11const executionContext = new ExecutionContext(frame, 'executionContextId', 'object');12console.log(formatInstance(page));13console.log(formatInstance(frame));14console.log(formatInstance(elementHandle));15console.log(formatInstance(jsHandle));16console.log(formatInstance(executionContext));17const { formatValue } = require('playwright/lib/server/common/inspectorSocket');18const { Page } = require('playwright/lib/server/chromium/crPage');19const { Frame } = require('playwright/lib/server/chromium/crFrame');20const { ElementHandle } = require('playwright/lib/server/chromium/crElementHandle');21const { JSHandle } = require('playwright/lib/server/chromium/crJSHandle');22const { ExecutionContext } = require('playwright/lib/server/chromium/crExecutionContext');23const page = new Page();24const frame = new Frame(page, 'frameId');25const elementHandle = new ElementHandle(frame, 'elementHandleId');26const jsHandle = new JSHandle(elementHandle, 'jsHandleId', 'object');27const executionContext = new ExecutionContext(frame, 'executionContextId', 'object');28console.log(formatValue(page));29console.log(formatValue(frame));30console.log(formatValue(elementHandle));31console.log(formatValue(jsHandle));32console.log(formatValue(executionContext));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright/lib/utils/utils');2const { Page } = require('playwright/lib/server/page');3const page = new Page();4console.log(formatInstance(page));5const { formatInstance } = require('playwright/lib/utils/utils');6const { Page } = require('playwright/lib/server/page');7const page = new Page();8console.log(formatInstance(page));9const { formatInstance } = require('playwright/lib/utils/utils');10const { Page } = require('playwright/lib/server/page');11const page = new Page();12console.log(formatInstance(page));13const { formatInstance } = require('playwright/lib/utils/utils');14const { Page } = require('playwright/lib/server/page');15const page = new Page();16console.log(formatInstance(page));17const { formatInstance } = require('playwright/lib/utils/utils');18const { Page } = require('playwright/lib/server/page');19const page = new Page();20console.log(formatInstance(page));21const { formatInstance } = require('playwright/lib/utils/utils');22const { Page } = require('playwright/lib/server/page');23const page = new Page();24console.log(formatInstance(page));25const { formatInstance } = require('playwright/lib/utils/utils');26const { Page } = require('playwright/lib/server/page');27const page = new Page();28console.log(formatInstance(page));29const { formatInstance } = require('playwright/lib/utils/utils');30const { Page } = require('playwright/lib/server/page');31const page = new Page();32console.log(formatInstance(page));33const { formatInstance } = require('playwright/lib/utils/utils');34const { Page } = require('playwright/lib/server/page');35const page = new Page();36console.log(formatInstance(page));37const { formatInstance } = require('playwright/lib/utils/utils');38const { Page } = require('playwright/lib/server/page');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright-core/lib/server/inspector/inspector');2const { ElementHandle } = require('playwright-core/lib/server/dom');3const element = new ElementHandle();4console.log(formatInstance(element));5const { formatValue } = require('playwright-core/lib/server/inspector/inspector');6const { ElementHandle } = require('playwright-core/lib/server/dom');7const element = new ElementHandle();8console.log(formatValue(element));9const { formatValue } = require('playwright-core/lib/server/inspector/inspector');10const { ElementHandle } = require('playwright-core/lib/server/dom');11const element = new ElementHandle();12console.log(formatValue({ element }));13const { formatValue } = require('playwright-core/lib/server/inspector/inspector');14const { ElementHandle } = require('playwright-core/lib/server/dom');15const element = new ElementHandle();16console.log(formatValue({ element: element }));17const { formatValue } = require('playwright-core/lib/server/inspector/inspector');18const { ElementHandle } = require('playwright-core/lib/server/dom');19const element = new ElementHandle();20console.log(formatValue({ element: element, element2: element }));21const { formatValue } = require('playwright-core/lib/server/inspector/inspector');22const { ElementHandle } = require

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright-core/lib/server/inspector/inspector');2const obj = {a:1,b:2,c:3};3console.log(formatInstance(obj));4const { formatValue } = require('playwright-core/lib/server/inspector/inspector');5const obj = {a:1,b:2,c:3};6console.log(formatValue(obj));7const { formatValue } = require('playwright-core/lib/server/inspector/inspector');8const obj = {a:1,b:2,c:3};9console.log(formatValue(obj));10const { formatValue } = require('playwright-core/lib/server/inspector/inspector');11const obj = {a:1,b:2,c:3};12console.log(formatValue(obj));13const { formatValue } = require('playwright-core/lib/server/inspector/inspector');14const obj = {a:1,b:2,c:3};15console.log(formatValue(obj));16const { formatValue } = require('playwright-core/lib/server/inspector/inspector');17const obj = {a:1,b:2,c:3};18console.log(formatValue(obj));19const { formatValue } = require('playwright-core/lib/server/inspector/inspector');20const obj = {a:1,b:2,c:3};21console.log(formatValue(obj));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright');2console.log(formatInstance('Hello World', 'String'));3const { formatValue } = require('playwright');4console.log(formatValue('Hello World', 'String'));5const { formatError } = require('playwright');6console.log(formatError('Hello World', 'String'));7const { formatAsCall } = require('playwright');8console.log(formatAsCall('Hello World', 'String'));9const { formatAsProperty } = require('playwright');10console.log(formatAsProperty('Hello World', 'String'));11const { formatAsGenerator } = require('playwright');12console.log(formatAsGenerator('Hello World', 'String'));13const { formatAsAsyncFunction } = require('playwright');14console.log(formatAsAsyncFunction('Hello World', 'String'));15const { formatAsPromise } = require('playwright');16console.log(formatAsPromise('Hello World', 'String'));17const { formatAsClassName } = require('playwright');18console.log(formatAsClassName('Hello World', 'String'));19const { formatAsRegExp } = require('playwright');20console.log(formatAsRegExp('Hello World', 'String'));21const { formatAsURL } = require('playwright');22console.log(formatAsURL('Hello World', 'String'));23const { formatAsFunction } =

Full Screen

Using AI Code Generation

copy

Full Screen

1const { formatInstance } = require('playwright/lib/server/frames.js');2const frame = await page.mainFrame();3const frameId = frame._id;4const frameInfo = formatInstance(frame);5console.log(frameInfo);6console.log(frameId);7const { formatInstance } = require('playwright/lib/server/frames.js');8const frame = await page.mainFrame();9const frameId = frame._id;10const frameInfo = formatInstance(frame);11console.log(frameInfo);12console.log(frameId);13const { formatInstance } = require('playwright/lib/server/frames.js');14const frame = await page.mainFrame();15const frameId = frame._id;16const frameInfo = formatInstance(frame);17console.log(frameInfo);18console.log(frameId);19const { formatInstance } = require('playwright/lib/server/frames.js');20const frame = await page.mainFrame();21const frameId = frame._id;22const frameInfo = formatInstance(frame);23console.log(frameInfo);24console.log(frameId);25const { formatInstance } = require('playwright/lib/server/frames.js');26const frame = await page.mainFrame();27const frameId = frame._id;28const frameInfo = formatInstance(frame);29console.log(frameInfo);30console.log(frameId);

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful