Best JavaScript code snippet using playwright-internal
Format.controller.js
Source:Format.controller.js
1sap.ui.controller("app.controllers.dialogs.format.Format", {2 onInit: function() {3 },4 onDataRefactor: function(data) {5 return $.extend(data, this.data);6 },7 onAfterRendering: function(html) {8 var _self = this;9 this.initServices();10 this.bindEvents();11 if (_self.coreServices.exhibition) {12 _self.processExhibition();13 }14 if (_self.getData().initLevel) {15 _self.initValues();16 }17 },18 bindEvents: function() {19 var _self = this;20 },21 initServices: function() {22 var _self = this;23 _self.layoutObject = _self.coreServices.layoutObject;24 //Initialize temporary objects25 _self.initTempFormat();26 var comboOptions = [{27 key: null,28 name: i18n('ALL')29 }].concat($.globalFunctions.getBlockOptions(_self.layoutObject, true, true));30 _self.comboBlocks = $('#comboBlocks').bindBaseSelect({31 options: comboOptions,32 disableSort: true,33 onChange: function(oldVal, newVal) {34 if (oldVal.key != newVal.key) {35 _self.updateFormatObject();36 if (newVal.key != null) {37 var comboOptions = [{38 key: null,39 name: i18n('ALL')40 }].concat(newVal.records);41 $('#comboRecords').html('');42 _self.comboRecords = $('#comboRecords').bindBaseSelect({43 tooltip: i18n('RECORD SELECT TOOLTIP'),44 options: comboOptions,45 disableSort: true,46 onChange: function(oldVal, newVal) {47 if (oldVal.key != newVal.key) {48 _self.updateFormatObject();49 if (newVal.key != null) {50 var comboOptions = [{51 key: null,52 name: i18n('ALL')53 }].concat(newVal.columns);54 $('#comboColumns').html('');55 _self.comboColumns = $('#comboColumns').bindBaseSelect({56 options: comboOptions,57 disableSort: true,58 tooltip: i18n('FIELD SELECT TOOLTIP'),59 onChange: function(oldVal, newVal) {60 if (oldVal.key != newVal.key && oldVal.key != '') {61 _self.updateFormatObject();62 _self.currentLevel = _self.getCurrentLevel();63 _self.renderTabData();64 }65 }66 });67 _self.comboColumns.setKey(null);68 } else {69 $('#comboColumns').html('');70 var fieldOptions = $.globalFunctions.getFieldColumnOptions(_self.layoutObject, _self.comboBlocks.getKey());71 if (fieldOptions.length) {72 _self.comboColumns = $('#comboColumns').bindBaseSelect({73 options: fieldOptions,74 disableSort: true,75 tooltip: i18n('FIELD SELECT TOOLTIP'),76 onChange: function(oldVal, newVal) {77 _self.updateFormatObject(true);78 _self.currentLevel = _self.getCurrentLevel(true);79 _self.currentLevel.columnData = newVal;80 _self.renderTabData();81 }82 });83 } else {84 _self.comboColumns = $('#comboColumns').bindBaseSelect({85 options: [],86 isDisabled: true,87 tooltip: i18n('FIELD SELECT TOOLTIP'),88 onChange: function(oldVal, newVal) {}89 });90 }91 }92 _self.currentLevel = _self.getCurrentLevel();93 _self.renderTabData();94 }95 }96 });97 _self.comboRecords.setKey(null); 98 } else {99 $('#comboRecords').html('');100 _self.comboRecords = $('#comboRecords').bindBaseSelect({101 options: comboOptions,102 disableSort: true,103 tooltip: i18n('RECORD SELECT TOOLTIP'),104 isDisabled: true,105 onChange: function(oldVal, newVal) {}106 });107 $('#comboColumns').html('');108 var fieldOptions = $.globalFunctions.getFieldColumnOptions(_self.layoutObject);109 if (fieldOptions.length) {110 _self.comboColumns = $('#comboColumns').bindBaseSelect({111 options: fieldOptions,112 disableSort: true,113 tooltip: i18n('FIELD SELECT TOOLTIP'),114 onChange: function(oldVal, newVal) {115 _self.updateFormatObject(true);116 _self.currentLevel = _self.getCurrentLevel(true);117 _self.currentLevel.columnData = newVal;118 _self.renderTabData();119 }120 });121 }else{122 $('#comboColumns').html('');123 _self.comboColumns = $('#comboColumns').bindBaseSelect({124 options: [],125 isDisabled: true,126 tooltip: i18n('FIELD SELECT TOOLTIP'),127 onChange: function(oldVal, newVal) {}128 });129 }130 }131 132 _self.currentLevel = _self.getCurrentLevel();133 _self.renderTabData();134 }135 },136 tooltip: i18n('BLOCK SELECT TOOLTIP')137 });138 _self.comboRecords = $('#comboRecords').bindBaseSelect({139 options: comboOptions,140 disableSort: true,141 isDisabled: true,142 onChange: function(oldVal, newVal) {},143 //tooltip: i18n('RECORD SELECT TOOLTIP')144 });145 _self.comboColumns = $('#comboColumns').bindBaseSelect({146 options: comboOptions,147 disableSort: true,148 isDisabled: true,149 onChange: function(oldVal, newVal) {},150 //tooltip: i18n('FIELD SELECT TOOLTIP')151 });152 _self.renderTabData();153 _self.currentLevel = _self.getCurrentLevel();154 _self.comboBlocks.setKey(null);155 },156 getCurrentLevel: function(isGeneralField) {157 var _self = this;158 var returnObject = {};159 if (_self.comboColumns.getKey()) {160 returnObject.level = "FIELD";161 } else if (_self.comboBlocks.getKey() && _self.comboRecords.getKey()) {162 returnObject.level = "RECORD";163 } else if (_self.comboBlocks.getKey()) {164 returnObject.level = "BLOCK";165 } else {166 returnObject.level = "ALL";167 }168 returnObject.blockId = _self.comboBlocks.getKey();169 returnObject.recordId = _self.comboRecords.getKey();170 returnObject.columnId = _self.comboColumns.getKey();171 returnObject.isGeneralField = isGeneralField;172 if (returnObject.level === "FIELD" && !isGeneralField) {173 returnObject.idStructure = _self.coreServices.layoutObject.blocks[returnObject.blockId].records[returnObject.recordId].columns[174 returnObject.columnId].idStructure;175 }176 return returnObject;177 },178 initValues: function() {179 var _self = this;180 var _data = _self.getData();181 if(_data.initLevel){ 182 _self.comboBlocks.setKey(_data.initLevel.blockId);183 _self.comboRecords.setKey(_data.initLevel.recordId);184 }185 if (_data.initLevel && _data.initLevel.canEditColumnName) {186 $('#comboColumns').html('');187 _self.comboColumns = $('#comboColumns').bindBaseInput({188 tooltip: i18n('CLICK/PRESS ENTER TO FILL COLUMN NAME'),189 required: true190 });191 _self.updateFormatObject();192 _self.currentLevel = _data.initLevel;193 _self.currentLevel.level = "FIELD";194 _self.renderTabData(_self.currentLevel);195 var column = _self.layoutObject.blocks[_data.initLevel.blockId].records[_data.initLevel.recordId].columns[_data.initLevel196 .columnId] || _self._data.initLevel.column || {};197 _self.comboColumns.setText(column.label || "");198 } else {199 if(_data.initLevel){200 _self.comboColumns.setKey(_data.initLevel.columnId);201 _self.comboColumns.disable();202 }203 }204 _self.comboBlocks.disable();205 _self.comboRecords.disable();206 },207 validate: function(){208 var _self = this; 209 var _data = _self._data;210 if(_data.initLevel && _data.initLevel.canEditColumnName){211 return _self.comboColumns.getText().length !== 0;212 }213 return true;214 },215 getColumnData: function(){216 var _self = this;217 _self.updateFormatObject();218 _self._data.initLevel.column.format = _self.formatObject.blocks[_self._data.initLevel.blockId].records[_self._data.initLevel.recordId].columns[_self._data.initLevel.columnId].format;219 return _self._data.initLevel.column;220 },221 getFormatData: function() {222 var _self = this;223 return _self.formatObject;224 },225 renderTabData: function(currentLevel) {226 var _self = this;227 var currFormat = {228 string: null,229 number: null,230 date: null,231 hour: null232 };233 var isHourFormat = false;234 var currentLevel = _self.currentLevel || _self.getCurrentLevel();235 $('#dfg-format-dialog .tab-content').html('');236 var type = "";237 switch (currentLevel.level) {238 case 'ALL':239 if (_self.formatObject.format) {240 currFormat = _self.formatObject.format;241 }242 break;243 case 'BLOCK':244 if (_self.formatObject.blocks[currentLevel.blockId].format) {245 currFormat = _self.formatObject.blocks[currentLevel.blockId].format;246 }247 break;248 case 'RECORD':249 if (_self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format) {250 currFormat = _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format;251 }252 break;253 case 'FIELD':254 var column;255 if (currentLevel.isGeneralField) {256 type = currentLevel.columnData.type;257 var commonFormat = null;258 var areCommon = true;259 var setFormat = function(blockId){260 for(var r in _self.layoutObject.blocks[blockId].records){261 if(!areCommon){262 break;263 }264 for(var c in _self.layoutObject.blocks[blockId].records[r].columns){265 var column = _self.layoutObject.blocks[blockId].records[r].columns[c];266 if(!column && _self._data.initLevel){267 column = _self._data.initLevel.column || {};268 }269 if(column.fieldId+"" === currentLevel.columnId.split("_")[0] && column.idStructure+"" === currentLevel.columnId.split("_")[1]){270 if(_self.formatObject.blocks[blockId].records[r].columns[c].format){271 if(!commonFormat){272 commonFormat = _self.formatObject.blocks[blockId].records[r].columns[c].format[type.toLowerCase()];273 }else{274 if(JSON.stringify(commonFormat) !== JSON.stringify(_self.formatObject.blocks[blockId].records[r].columns[c].format[type.toLowerCase()])){275 commonFormat = null;276 areCommon = false;277 break;278 }279 }280 }281 break;282 }283 }284 }285 };286 if(currentLevel.blockId){287 setFormat(currentLevel.blockId);288 }else{289 for(var b in _self.layoutObject.blocks){290 if(!areCommon){291 break;292 }293 setFormat(b);294 }295 }296 currFormat[type.toLowerCase()] = commonFormat;297 } else {298 column = _self.coreServices.layoutObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId];299 if(!column && _self._data.initLevel){300 column = _self._data.initLevel.column || {};301 }302 type = $.globalFunctions.getColumnType(column, _self.coreServices.structure, true);303 if (_self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format) {304 if (type === "STRING") {305 currFormat.string = _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format306 .string;307 }308 if (type === "NUMBER") {309 currFormat.number = _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format310 .number;311 }312 if (type === "DATE") {313 currFormat.date = _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format314 .date;315 }316 if (type === "HOUR") {317 currFormat.hour = _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format318 .hour;319 }320 }321 }322 default:323 }324 if (currentLevel.level == 'ALL' || currentLevel.level == 'BLOCK' || currentLevel.level == 'RECORD') {325 _self.tabController = $('#dfg-format-dialog .tab-content').bindBaseTabs({326 tab: [{327 title: i18n('STRING'),328 icon: "string",329 iconColor: "white",330 iconFont: "Sign-and-Symbols",331 viewName: "app.views.dialogs.format.FormatString",332 viewData: {333 format: currFormat.string334 },335 tooltip: i18n('STRING TAB TOOLTIP')336 }, {337 title: i18n('NUMBER'),338 icon: "number",339 iconColor: "white",340 iconFont: "Sign-and-Symbols",341 viewName: "app.views.dialogs.format.FormatNumber",342 viewData: {343 format: currFormat.number344 },345 tooltip: i18n('NUMBER TAB TOOLTIP')346 }, {347 title: i18n('DATE'),348 icon: "calendar",349 iconColor: "white",350 iconFont: "Time-and-Date",351 viewName: "app.views.dialogs.format.FormatDate",352 viewData: {353 format: currFormat.date,354 },355 tooltip: i18n('DATE TAB TOOLTIP')356 }, {357 title: i18n('HOUR'),358 icon: "clock",359 iconColor: "white",360 iconFont: "Time-and-Date",361 viewName: "app.views.dialogs.format.FormatDate",362 viewData: {363 format: currFormat.hour,364 isHourFormat: true365 },366 tooltip: i18n('HOUR TAB TOOLTIP')367 }],368 type: "boxes",369 wrapperClass: "wrapperClass"370 })371 } else {372 var tabs = [];373 if (type === "STRING") {374 tabs.push({375 title: i18n('STRING'),376 icon: "string",377 iconColor: "white",378 iconFont: "Sign-and-Symbols",379 viewName: "app.views.dialogs.format.FormatString",380 viewData: {381 services: _self.services,382 format: currFormat.string383 }384 });385 }386 if (type === "NUMBER") {387 tabs.push({388 title: i18n('NUMBER'),389 icon: "number",390 iconColor: "white",391 iconFont: "Sign-and-Symbols",392 viewName: "app.views.dialogs.format.FormatNumber",393 viewData: {394 format: currFormat.number395 }396 });397 }398 if (type === "DATE") {399 tabs.push({400 title: i18n('DATE'),401 icon: "calendar",402 iconColor: "white",403 iconFont: "Time-and-Date",404 viewName: "app.views.dialogs.format.FormatDate",405 viewData: {406 format: currFormat.date407 }408 });409 }410 if (type === "HOUR") {411 tabs.push({412 title: i18n('HOUR'),413 icon: "calendar",414 iconColor: "white",415 iconFont: "Time-and-Date",416 viewName: "app.views.dialogs.format.FormatDate",417 viewData: {418 format: currFormat.hour,419 isHourFormat: true420 }421 });422 }423 _self.tabController = $('#dfg-format-dialog .tab-content').bindBaseTabs({424 tab: tabs,425 type: "boxes",426 wrapperClass: "wrapperClass"427 });428 429 }430 if (_self.coreServices.exhibition) {431 _self.processExhibition();432 }433 },434 updateFormatObject: function() {435 var _self = this;436 var _data = _self._data;437 var currentLevel = _self.currentLevel;438 switch (currentLevel.level) {439 case 'ALL':440 _self.formatObject.format = {};441 _self.formatObject.format.string = _self.tabController.getInnerController(0).getOwnData();442 _self.formatObject.format.number = _self.tabController.getInnerController(1).getOwnData();443 _self.formatObject.format.date = _self.tabController.getInnerController(2).getOwnData();444 _self.formatObject.format.hour = _self.tabController.getInnerController(3).getOwnData();445 break;446 case 'BLOCK':447 _self.formatObject.blocks[currentLevel.blockId].format = {};448 _self.formatObject.blocks[currentLevel.blockId].format.string = _self.tabController.getInnerController(0).getOwnData();449 _self.formatObject.blocks[currentLevel.blockId].format.number = _self.tabController.getInnerController(1).getOwnData();450 _self.formatObject.blocks[currentLevel.blockId].format.date = _self.tabController.getInnerController(2).getOwnData();451 _self.formatObject.blocks[currentLevel.blockId].format.hour = _self.tabController.getInnerController(3).getOwnData();452 break;453 case 'RECORD':454 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format = {};455 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format.string = _self.tabController.getInnerController(456 0).getOwnData();457 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format.number = _self.tabController.getInnerController(458 1).getOwnData();459 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format.date = _self.tabController.getInnerController(2)460 .getOwnData();461 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].format.hour = _self.tabController.getInnerController(3)462 .getOwnData();463 break;464 case 'FIELD':465 var assignFormat = function(format, type) {466 var assignFormatXBlock = function(blockId) {467 for (var r in _self.layoutObject.blocks[blockId].records) {468 for (var c in _self.layoutObject.blocks[blockId].records[r].columns) {469 var column = JSON.parse(JSON.stringify(_self.layoutObject.blocks[blockId].records[r].columns[c]));470 if(!column && _self._data.initLevel){471 column = _self._data.initLevel.column || {};472 } 473 if (column.fieldId) {474 if (column.fieldId+"" === currentLevel.columnId.split("_")[0] && column.idStructure+"" === currentLevel.columnId.split("_")[1]) {475 if (!_self.formatObject.blocks[blockId].records[r].columns[c].format) {476 _self.formatObject.blocks[blockId].records[r].columns[c].format = {};477 }478 switch (type) { 479 case "STRING":480 _self.formatObject.blocks[blockId].records[r].columns[c].format.string = format;481 break;482 case "NUMBER":483 _self.formatObject.blocks[blockId].records[r].columns[c].format.number = format;484 break;485 case "DATE":486 _self.formatObject.blocks[blockId].records[r].columns[c].format.date = format;487 break;488 case "HOUR":489 _self.formatObject.blocks[blockId].records[r].columns[c].format.hour = format;490 break;491 }492 }493 }494 }495 }496 };497 if (currentLevel.blockId) {498 assignFormatXBlock(currentLevel.blockId);499 } else {500 for (var b in _self.layoutObject.blocks) {501 assignFormatXBlock(b);502 }503 }504 };505 if (!currentLevel.isGeneralField) {506 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format = {507 string: null,508 number: null,509 date: null,510 hour: null511 };512 } else {513 assignFormat(null, "STRING");514 assignFormat(null, "NUMBER");515 assignFormat(null, "DATE");516 assignFormat(null, "HOUR");517 }518 var column, type;519 if (currentLevel.isGeneralField) {520 type = currentLevel.columnData.type;521 } else {522 column = _self.coreServices.layoutObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId];523 if(!column && _self._data.initLevel){524 column = _self._data.initLevel.column || {};525 }526 }527 if (_data.initLevel && _data.initLevel.canEditColumnName && _self.comboColumns.getText()) {528 column.label = _self.comboColumns.getText();529 }530 type = type || $.globalFunctions.getColumnType(column, _self.coreServices.structure, true);531 var format = _self.tabController.getInnerController(0).getOwnData();532 if (type === "STRING") {533 if (currentLevel.isGeneralField) {534 assignFormat(format, type);535 } else {536 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.string = format;537 }538 }539 if (type === "NUMBER") {540 if (currentLevel.isGeneralField) {541 assignFormat(format, type);542 } else {543 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.number = format;544 }545 }546 if (type === "DATE") {547 if (currentLevel.isGeneralField) {548 assignFormat(format, type);549 } else {550 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.date = format;551 }552 }553 if (type === "HOUR") {554 if (currentLevel.isGeneralField) {555 assignFormat(format, type);556 } else {557 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.hour = format;558 }559 }560 if (!currentLevel.isGeneralField) {561 if (!(_self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.string ||562 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.number ||563 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.date ||564 _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format.hour)) {565 delete _self.formatObject.blocks[currentLevel.blockId].records[currentLevel.recordId].columns[currentLevel.columnId].format;566 }567 }568 default:569 }570 },571 initTempFormat: function() {572 var _self = this;573 _self.formatObject = {};574 _self.formatObject.blocks = {}575 _self.formatObject.format = _self.coreServices.layoutObject.format;576 for (var i in _self.layoutObject.blocks) {577 _self.formatObject.blocks[i] = {}578 _self.formatObject.blocks[i].format = _self.layoutObject.blocks[i].format579 _self.formatObject.blocks[i].records = {};580 for (var j in _self.layoutObject.blocks[i].records) {581 _self.formatObject.blocks[i].records[j] = {};582 _self.formatObject.blocks[i].records[j].format = _self.layoutObject.blocks[i].records[j].format;583 _self.formatObject.blocks[i].records[j].columns = {};584 for (var k in _self.layoutObject.blocks[i].records[j].columns) {585 _self.formatObject.blocks[i].records[j].columns[k] = {};586 _self.formatObject.blocks[i].records[j].columns[k].format = _self.layoutObject.blocks[i].records[j].columns[k].format;587 }588 }589 }590 if(_self._data.initLevel){591 if(!_self.formatObject.blocks[_self._data.initLevel.blockId].records[_self._data.initLevel.recordId].columns[_self._data.initLevel.columnId]){592 _self.formatObject.blocks[_self._data.initLevel.blockId].records[_self._data.initLevel.recordId].columns[_self._data.initLevel.columnId] = {593 "format": {}594 };595 }596 }597 },598 processExhibition: function() {599 var mainCrystal = $('<div>').addClass('dfg-crystal').addClass('dfg-format');600 $('.newFile .dialog-content #baseTabs-wrapper').append(mainCrystal);601 }...
jquery.countdown.js
Source:jquery.countdown.js
1/*!2 * The Final Countdown for jQuery v2.0.4 (http://hilios.github.io/jQuery.countdown/)3 * Copyright (c) 2014 Edson Hilios4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of6 * this software and associated documentation files (the "Software"), to deal in7 * the Software without restriction, including without limitation the rights to8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of9 * the Software, and to permit persons to whom the Software is furnished to do so,10 * subject to the following conditions:11 * 12 * The above copyright notice and this permission notice shall be included in all13 * copies or substantial portions of the Software.14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.21 */22(function(factory) {23 "use strict";24 if (typeof define === "function" && define.amd) {25 define([ "jquery" ], factory);26 } else {27 factory(jQuery);28 }29})(function($) {30 "use strict";31 var PRECISION = 100;32 var instances = [], matchers = [];33 matchers.push(/^[0-9]*$/.source);34 matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source);35 matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source);36 matchers = new RegExp(matchers.join("|"));37 function parseDateString(dateString) {38 if (dateString instanceof Date) {39 return dateString;40 }41 if (String(dateString).match(matchers)) {42 if (String(dateString).match(/^[0-9]*$/)) {43 dateString = Number(dateString);44 }45 if (String(dateString).match(/\-/)) {46 dateString = String(dateString).replace(/\-/g, "/");47 }48 return new Date(dateString);49 } else {50 throw new Error("Couldn't cast `" + dateString + "` to a date object.");51 }52 }53 var DIRECTIVE_KEY_MAP = {54 Y: "years",55 m: "months",56 w: "weeks",57 d: "days",58 D: "totalDays",59 H: "hours",60 M: "minutes",61 S: "seconds"62 };63 function strftime(offsetObject) {64 return function(format) {65 var directives = format.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);66 if (directives) {67 for (var i = 0, len = directives.length; i < len; ++i) {68 var directive = directives[i].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/), regexp = new RegExp(directive[0]), modifier = directive[1] || "", plural = directive[3] || "", value = null;69 directive = directive[2];70 if (DIRECTIVE_KEY_MAP.hasOwnProperty(directive)) {71 value = DIRECTIVE_KEY_MAP[directive];72 value = Number(offsetObject[value]);73 }74 if (value !== null) {75 if (modifier === "!") {76 value = pluralize(plural, value);77 }78 if (modifier === "") {79 if (value < 10) {80 value = "0" + value.toString();81 }82 }83 format = format.replace(regexp, value.toString());84 }85 }86 }87 format = format.replace(/%%/, "%");88 return format;89 };90 }91 function pluralize(format, count) {92 var plural = "s", singular = "";93 if (format) {94 format = format.replace(/(:|;|\s)/gi, "").split(/\,/);95 if (format.length === 1) {96 plural = format[0];97 } else {98 singular = format[0];99 plural = format[1];100 }101 }102 if (Math.abs(count) === 1) {103 return singular;104 } else {105 return plural;106 }107 }108 var Countdown = function(el, finalDate, callback) {109 this.el = el;110 this.$el = $(el);111 this.interval = null;112 this.offset = {};113 this.instanceNumber = instances.length;114 instances.push(this);115 this.$el.data("countdown-instance", this.instanceNumber);116 if (callback) {117 this.$el.on("update.countdown", callback);118 this.$el.on("stoped.countdown", callback);119 this.$el.on("finish.countdown", callback);120 }121 this.setFinalDate(finalDate);122 this.start();123 };124 $.extend(Countdown.prototype, {125 start: function() {126 if (this.interval !== null) {127 clearInterval(this.interval);128 }129 var self = this;130 this.update();131 this.interval = setInterval(function() {132 self.update.call(self);133 }, PRECISION);134 },135 stop: function() {136 clearInterval(this.interval);137 this.interval = null;138 this.dispatchEvent("stoped");139 },140 pause: function() {141 this.stop.call(this);142 },143 resume: function() {144 this.start.call(this);145 },146 remove: function() {147 this.stop();148 instances[this.instanceNumber] = null;149 delete this.$el.data().countdownInstance;150 },151 setFinalDate: function(value) {152 this.finalDate = parseDateString(value);153 },154 update: function() {155 if (this.$el.closest("html").length === 0) {156 this.remove();157 return;158 }159 this.totalSecsLeft = this.finalDate.getTime() - new Date().getTime();160 this.totalSecsLeft = Math.ceil(this.totalSecsLeft / 1e3);161 this.totalSecsLeft = this.totalSecsLeft < 0 ? 0 : this.totalSecsLeft;162 this.offset = {163 seconds: this.totalSecsLeft % 60,164 minutes: Math.floor(this.totalSecsLeft / 60) % 60,165 hours: Math.floor(this.totalSecsLeft / 60 / 60) % 24,166 days: Math.floor(this.totalSecsLeft / 60 / 60 / 24) % 7,167 totalDays: Math.floor(this.totalSecsLeft / 60 / 60 / 24),168 weeks: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 7),169 months: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 30),170 years: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 365)171 };172 if (this.totalSecsLeft === 0) {173 this.stop();174 this.dispatchEvent("finish");175 } else {176 this.dispatchEvent("update");177 }178 },179 dispatchEvent: function(eventName) {180 var event = $.Event(eventName + ".countdown");181 event.finalDate = this.finalDate;182 event.offset = $.extend({}, this.offset);183 event.strftime = strftime(this.offset);184 this.$el.trigger(event);185 }186 });187 $.fn.countdown = function() {188 var argumentsArray = Array.prototype.slice.call(arguments, 0);189 return this.each(function() {190 var instanceNumber = $(this).data("countdown-instance");191 if (instanceNumber !== undefined) {192 var instance = instances[instanceNumber], method = argumentsArray[0];193 if (Countdown.prototype.hasOwnProperty(method)) {194 instance[method].apply(instance, argumentsArray.slice(1));195 } else if (String(method).match(/^[$A-Z_][0-9A-Z_$]*$/i) === null) {196 instance.setFinalDate.call(instance, method);197 instance.start();198 } else {199 $.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi, method));200 }201 } else {202 new Countdown(this, argumentsArray[0], argumentsArray[1]);203 }204 });205 };206});207// initialization for plugin208$(function(){209 // formatting for date yy/mm/dd hh/mm:ss210 Number.prototype.padLeft = function(base,chr){211 var len = (String(base || 10).length - String(this).length)+1;212 return len > 0? new Array(len).join(chr || '0')+this : this;213 }214 var d = new Date(),215 dformat = [216 07, // month217 09, // day218 2014 // year219 ]220 .join('/') + ' ' + [221 15, // hours222 10, // minutes223 20 // seconds224 ]225 .join(':');226 // end formatting for date227 /*code for demonstration*/228 d = new Date()229 dformat = [230 d.getFullYear(),231 (d.getMonth() + 2).padLeft(), // set current date + 2 month232 d.getDate().padLeft()233 ]234 .join('/') + ' ' + [235 d.getHours().padLeft(),236 d.getMinutes().padLeft(),237 d.getSeconds().padLeft()238 ]239 .join(':');240 /*end code for demonstration*/241 var formatObject = {242 separatorClass: 'separator',243 separatorValue: ':',244 yearsClass: 'years',245 weeksClass: 'weeks',246 daysClass: 'days',247 hoursClass: 'hours',248 minutesClass: 'minutes',249 secondsClass: 'seconds',250 };251 $('#counter')252 .countdown(dformat)253 .on('update.countdown', function(event) {254 $(this).html(event.strftime(255 '<span class="' + formatObject.daysClass + '">%D</span>'256 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'257 + '<span class="' + formatObject.hoursClass + '">%H</span>'258 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'259 + '<span class="' + formatObject.minutesClass + '">%M</span>'260 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'261 + '<span class="' + formatObject.secondsClass + '">%S</span>')262 );263 });264 $('#counter2')265 .countdown(dformat)266 .on('update.countdown', function(event) {267 $(this).html(event.strftime(''268 + '<span class="' + formatObject.weeksClass +'">%-w</span> week%!w '269 + '<span class="' + formatObject.daysClass + '">%D</span>'270 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'271 + '<span class="' + formatObject.hoursClass + '">%H</span>'272 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'273 + '<span class="' + formatObject.minutesClass + '">%M</span>'274 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'275 + '<span class="' + formatObject.secondsClass + '">%S</span>')276 );277 });278 $('#counter3')279 .countdown(dformat)280 .on('update.countdown', function(event) {281 $(this).html(event.strftime(''282 + '<span class="' + formatObject.yearsClass +'">%-Y</span> year%!Y '283 + '<span class="' + formatObject.monthClass + '">%m</span> month%!m '284 + '<span class="' + formatObject.daysClass + '">%D</span>'285 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'286 + '<span class="' + formatObject.hoursClass + '">%H</span>'287 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'288 + '<span class="' + formatObject.minutesClass + '">%M</span>'289 + '<span class="' + formatObject.separatorClass + '">' + formatObject.separatorValue + '</span>'290 + '<span class="' + formatObject.secondsClass + '">%S</span>')291 );292 });293 294 $('#counter, #counter2, #counter3')295 .on('finish.countdown', function(event) {296 $(this).html('This offer has expired!')297 .parent().addClass('disabled'); 298 });...
int14.pipeline.store.test.js
Source:int14.pipeline.store.test.js
1const Pipeline = require('../../classes/pipeline');2const Database = require('../../classes/database');3const SQLTemplate = require('../../classes/sqltemplate');4const { QueryConstructionError, QueryExecutionError, EmptyResponseError } = require('../../classes/errors');5const creds = require('../../secrets/dbconnection.json')['test'];6let pipe, db;7beforeAll(() => {8 db = new Database(creds);9 pipe = new Pipeline(db);10});11afterAll(() => {12 db.end();13});14describe('Integration Test 14 - Pipeline.Store', () => {15 test('Class 1: single reading query', () => {16 let queries = {17 test: {18 text: 'SELECT userid FROM Account WHERE fullname = \'Testy McTestface\'',19 },20 };21 let order = ['test'];22 let formatObject = {};23 let template = new SQLTemplate(queries, order);24 return pipe.Store(template, formatObject).then(res => {25 expect(res).toHaveLength(1);26 expect(res[0]).toHaveLength(1);27 expect(res[0][0]).toHaveProperty('userid', 1);28 });29 });30 test('Class 2: single writing query', () => {31 let queries = {32 test: {33 text: 'INSERT INTO Account (FullName, Email, PassHash, DoB) VALUES (\'Kevin McTestface\', \'int14c2@gmail.com\', \'$2a$12$zmdLgiclytrKGXRF7iNDfufusYm1YNEy7sRTEPg7W3LoLIfY/hBA6\', \'1986-03-12\')',34 },35 };36 let order = ['test'];37 let formatObject = {};38 let template = new SQLTemplate(queries, order);39 return pipe.Store(template, formatObject).then(res => {40 expect(res).toHaveLength(1);41 expect(res[0]).toHaveLength(0);42 return db.simpleQuery('SELECT userid FROM Account WHERE email = \'int14c2@gmail.com\'');43 }).then(res => {44 expect(res).toHaveLength(1);45 expect(res[0]).toHaveLength(1);46 expect(res[0][0]).toHaveProperty('userid');47 });48 });49 test('Class 3: multiple queries', () => {50 let queries = {51 test1: {52 text: 'SELECT userid FROM Account WHERE fullname = \'Testy McTestface\'',53 },54 test2: {55 text: 'SELECT userid FROM Account WHERE fullname = \'Ronnie Omelettes\'',56 },57 };58 let order = ['test1', 'test2'];59 let formatObject = {};60 let template = new SQLTemplate(queries, order);61 return pipe.Store(template, formatObject).then(res => {62 expect(res).toHaveLength(2);63 expect(res[0]).toHaveLength(1);64 expect(res[0][0]).toHaveProperty('userid', 1);65 expect(res[1]).toHaveLength(1);66 expect(res[1][0]).toHaveProperty('userid', 3);67 });68 });69 test('Class 4: parameterised query with input object', () => {70 let queries = {71 test: {72 text: 'SELECT userid FROM Account WHERE fullname = $1',73 values: [74 {from_input: 'username'},75 ],76 },77 };78 let order = ['test'];79 let formatObject = {username: 'Testy McTestface'};80 let template = new SQLTemplate(queries, order);81 return pipe.Store(template, formatObject).then(res => {82 expect(res).toHaveLength(1);83 expect(res[0]).toHaveLength(1);84 expect(res[0][0]).toHaveProperty('userid', 1);85 });86 });87 test('Class 5: parameterised query with callable', () => {88 let queries = {89 test1: {90 text: 'SELECT NOW() AS now',91 },92 test2: {93 text: 'SELECT userid FROM Account WHERE fullname = $1',94 values: [95 (inp, qs) => qs.length === 0 || inp['username'],96 ],97 },98 };99 let order = ['test1', 'test2'];100 let formatObject = {username: 'Testy McTestface'};101 let template = new SQLTemplate(queries, order, {drop_from_results: ['test1']});102 return pipe.Store(template, formatObject).then(res => {103 expect(res).toHaveLength(1);104 expect(res[0]).toHaveLength(1);105 expect(res[0][0]).toHaveProperty('userid', 1);106 });107 });108 test('Class 6: parameterised query with backreference', () => {109 let queries = {110 test1: {111 text: 'INSERT INTO Account (FullName, Email, PassHash, DoB) VALUES (\'Kevin McTestface\', \'int14c6@gmail.com\', \'$2a$12$zmdLgiclytrKGXRF7iNDfufusYm1YNEy7sRTEPg7W3LoLIfY/hBA6\', \'1986-03-12\') RETURNING userid',112 },113 test2: {114 text: 'SELECT fullname FROM Account WHERE userid = $1',115 values: [116 {from_query: ['test1', 'userid']},117 ],118 },119 };120 let order = ['test1', 'test2'];121 let formatObject = {};122 let template = new SQLTemplate(queries, order);123 return pipe.Store(template, formatObject).then(res => {124 expect(res).toHaveLength(2);125 expect(res[0]).toHaveLength(1);126 expect(res[0][0]).toHaveProperty('userid');127 expect(res[1]).toHaveLength(1);128 expect(res[1][0]).toHaveProperty('fullname', 'Kevin McTestface');129 });130 });131 test('Class 7: conditional query', () => {132 let queries = {133 test: {134 text: 'SELECT userid FROM Account WHERE fullname = \'Testy McTestface\'',135 condition: inp => formatObject['do_things'],136 },137 };138 let order = ['test'];139 let formatObject = {do_things: false};140 let template = new SQLTemplate(queries, order);141 return pipe.Store(template, formatObject).then(res => {142 expect(res).toHaveLength(0);143 });144 });145 test('Class 8: multiple-execution query', () => {146 let queries = {147 test: {148 text: 'SELECT userid FROM Account WHERE fullname = \'Testy McTestface\'',149 times: inp => formatObject['do_things'],150 },151 };152 let order = ['test'];153 let formatObject = {do_things: 5};154 let template = new SQLTemplate(queries, order);155 return pipe.Store(template, formatObject).then(res => {156 expect(res).toHaveLength(5);157 for (let i=0; i<5; i++) {158 expect(res[i]).toHaveLength(1);159 expect(res[i][0]).toHaveProperty('userid', 1);160 }161 });162 });163 test('Class 9: unbuildable query', () => {164 let queries = {165 test: {166 text: 'SELECT userid FROM Account WHERE fullname = $1',167 values: [168 () => {throw new Error()},169 ],170 },171 };172 let order = ['test'];173 let formatObject = {somekeys: 'values'};174 let template = new SQLTemplate(queries, order);175 return expect(pipe.Store(template, formatObject)).rejects.toBeInstanceOf(QueryConstructionError);176 });177 test('Class 10: exceptional, simple query', () => {178 let queries = {179 test: {180 text: 'AMRGJBE userid FROM Account WHERE fullname = \'Testy McTestface\'',181 },182 };183 let order = ['test'];184 let formatObject = {};185 let template = new SQLTemplate(queries, order);186 return expect(pipe.Store(template, formatObject)).rejects.toBeInstanceOf(QueryExecutionError);187 });188 test('Class 11: exceptional, complex query', () => {189 let queries = {190 test1: {191 text: 'AMRGJBE userid FROM Account WHERE fullname = \'Testy McTestface\'',192 },193 test2: {194 text: 'SELECT userid FROM Account WHERE fullname = \'Testy McTestface\'',195 },196 };197 let order = ['test1', 'test2'];198 let formatObject = {};199 let template = new SQLTemplate(queries, order);200 return expect(pipe.Store(template, formatObject)).rejects.toBeInstanceOf(QueryExecutionError);201 });202 test('Class 12: query with no results, where error_on_empty_response is true', () => {203 let queries = {204 test: {205 text: 'SELECT userid FROM Account WHERE fullname = \'Nobody\'',206 },207 };208 let order = ['test'];209 let formatObject = {};210 let template = new SQLTemplate(queries, order, {error_on_empty_response: true});211 return expect(pipe.Store(template, formatObject)).rejects.toBeInstanceOf(EmptyResponseError);212 });...
StyleSheet.js
Source:StyleSheet.js
1/*class flash.text.StyleSheet*/2/*3import flash.events.*;4*/5(function ()6{7 "use strict";8 9 var d = {};10 11 /*private*/12 d/*var*/._css/*Object*/ = null;13 14 /*private*/15 d.get__styles = function ()/*Object*/16 {17 18 };19 20 /*private*/21 d.set__styles = function (styles/*Object*/)/*void*/22 {23 24 };25 26 /*public*/27 d.get_styleNames = function ()/*Array*/28 {29 30 var _loc_1/*Array*/ = null;31 var _loc_2/*Object*/ = null;32 _loc_1 = [];33 34 for (_loc_2 in this._css)35 {36 _loc_1.push(_loc_2);37 38 }39 return _loc_1;40 41 };42 43 44 /*public*/45 d.StyleSheet = function ()46 {47 this.EventDispatcher_constructor();48 this._css =49 {};50 this.set__styles(51 {}52 );53 return;54 55 };56 57 /*private*/58 d._copy = function (o/*Object*/)/*Object*/59 {60 61 var _loc_2/*Object*/ = null;62 var _loc_3/*Object*/ = null;63 64 if (typeof(o) != "object")65 {66 return null;67 68 }69 _loc_2 =70 {};71 72 for (_loc_3 in o)73 {74 _loc_2[ _loc_3 ] = o[ _loc_3 ];75 76 }77 return _loc_2;78 79 };80 81 /*private*/82 d._parseCSSFontFamily = function (fontFamily/*String*/)/*String*/83 {84 85 };86 87 /*private*/88 d._parseCSSInternal = function (cssText/*String*/)/*Object*/89 {90 91 };92 93 /*private*/94 d._parseColor = function (color/*String*/)/*uint*/95 {96 97 };98 99 /*private*/100 d._update = function ()/*void*/101 {102 103 };104 105 /*public*/106 d.clear = function ()/*void*/107 {108 this._css =109 {};110 this.set__styles(111 {}112 );113 this._update();114 return;115 116 };117 118 /*private*/119 d.doTransform = function (n/*String*/)/*void*/120 {121 122 var _loc_2/*TextFormat*/ = null;123 _loc_2 = this.transform(this._css[ n ]);124 this.get__styles()[ n ] = _loc_2;125 return;126 127 };128 129 /*public*/130 d.getStyle = function (styleName/*String*/)/*Object*/131 {132 return this._copy(this._css[ styleName.toLowerCase() ]);133 134 };135 136 /*public*/137 d.parseCSS = function (CSSText/*String*/)/*void*/138 {139 140 var _loc_2/*Object*/ = null;141 var _loc_3/*String*/ = null;142 _loc_2 = this._parseCSSInternal(CSSText);143 144 if (typeof(_loc_2) == "null")145 {146 return;147 148 }149 150 for (_loc_3 in _loc_2)151 {152 this._css[ _loc_3 ] = this._copy(_loc_2[ _loc_3 ]);153 this.doTransform(_loc_3);154 155 }156 this._update();157 return;158 159 };160 161 /*public*/162 d.setStyle = function (styleName/*String*/, styleObject/*Object*/)/*void*/163 {164 165 var _loc_3/*String*/ = null;166 _loc_3 = styleName.toLowerCase();167 this._css[ _loc_3 ] = this._copy(styleObject);168 this.doTransform(_loc_3);169 this._update();170 return;171 172 };173 174 /*public*/175 d.transform = function (formatObject/*Object*/)/*TextFormat*/176 {177 178 var _loc_2/*TextFormat*/ = null;179 var _loc_3/* * */ = undefined;180 181 if (formatObject == null)182 {183 return null;184 185 }186 _loc_2 = new flash.text.TextFormat();187 _loc_3 = formatObject.textAlign;188 189 if (_loc_3)190 {191 _loc_2.set_align(_loc_3);192 193 }194 _loc_3 = formatObject.fontSize;195 196 if (_loc_3)197 {198 _loc_3 = parseInt(_loc_3);199 200 if (_loc_3 > 0)201 {202 _loc_2.set_size(_loc_3);203 204 }205 206 }207 _loc_3 = formatObject.textDecoration;208 209 if (_loc_3 == "none")210 {211 _loc_2.set_underline(false);212 213 }214 else if (_loc_3 == "underline")215 {216 _loc_2.set_underline(true);217 218 }219 _loc_3 = formatObject.marginLeft;220 221 if (_loc_3)222 {223 _loc_2.set_leftMargin(parseInt(_loc_3));224 225 }226 _loc_3 = formatObject.marginRight;227 228 if (_loc_3)229 {230 _loc_2.set_rightMargin(parseInt(_loc_3));231 232 }233 _loc_3 = formatObject.leading;234 235 if (_loc_3)236 {237 _loc_2.set_leading(parseInt(_loc_3));238 239 }240 _loc_3 = formatObject.kerning;241 242 if (_loc_3 == "true")243 {244 _loc_2.set_kerning(1);245 246 }247 else if (_loc_3 == "false")248 {249 _loc_2.set_kerning(0);250 251 }252 else253 {254 _loc_2.set_kerning(parseInt(_loc_3));255 256 }257 _loc_3 = formatObject.letterSpacing;258 259 if (_loc_3)260 {261 _loc_2.set_letterSpacing(parseFloat(_loc_3));262 263 }264 _loc_3 = formatObject.fontFamily;265 266 if (_loc_3)267 {268 _loc_2.set_font(this._parseCSSFontFamily(_loc_3));269 270 }271 _loc_3 = formatObject.display;272 273 if (_loc_3)274 {275 _loc_2.set_display(_loc_3);276 277 }278 _loc_3 = formatObject.fontWeight;279 280 if (_loc_3 == "bold")281 {282 _loc_2.set_bold(true);283 284 }285 else if (_loc_3 == "normal")286 {287 _loc_2.set_bold(false);288 289 }290 _loc_3 = formatObject.fontStyle;291 292 if (_loc_3 == "italic")293 {294 _loc_2.set_italic(true);295 296 }297 else if (_loc_3 == "normal")298 {299 _loc_2.set_italic(false);300 301 }302 _loc_3 = formatObject.textIndent;303 304 if (_loc_3)305 {306 _loc_2.set_indent(parseInt(_loc_3));307 308 }309 _loc_3 = formatObject.color;310 311 if (_loc_3)312 {313 _loc_3 = this._parseColor(_loc_3);314 315 if (_loc_3 != null)316 {317 _loc_2.set_color(_loc_3);318 319 }320 321 }322 return _loc_2;323 324 };325 326 327 var s = {};328 329 s.__init__ = function ()330 {331 /*super*/332 /*public*/333 this.prototype.EventDispatcher_constructor = this.__base__;334 };335 336 337 flash.addDescription("flash.text.StyleSheet", d, "flash.events.EventDispatcher", s, null);338 339}
...
xmlBuilders.js
Source:xmlBuilders.js
...5exports.buildAddCustomerXML = function (customer, mpAuth, xmlOptions) {6 var data = {};7 data.verification = mpAuth;8 data.command = 'add-consumer';9 data.request = utils.formatObject(customer, models.addCustomer);10 return xmlBuilder(xmlOptions).buildObject({11 'api-request': data12 });13};14exports.buildUpdateCustomerXML = function (customer, mpAuth, xmlOptions) {15 var data = {};16 data.verification = mpAuth;17 data.command = 'update-consumer';18 data.request = utils.formatObject(customer, models.updateCustomer);19 return xmlBuilder(xmlOptions).buildObject({20 'api-request': data21 });22};23exports.buildDeleteCustomerXML = function (customerId, mpAuth, xmlOptions) {24 var data = {};25 data.verification = mpAuth;26 data.command = 'delete-consumer';27 data.request = utils.formatObject(customerId, models.deleteCustomer);28 return xmlBuilder(xmlOptions).buildObject({29 'api-request': data30 });31};32exports.buildZeroDollarXML = function (zeroDollar, mpAPIVersion, mpAuth, xmlOptions) {33 var data = {};34 data.version = mpAPIVersion;35 data.verification = mpAuth;36 data.order = {37 zeroDollar: utils.formatObject(zeroDollar, models.zeroDollar)38 };39 return xmlBuilder(xmlOptions).buildObject({40 'transaction-request': data41 });42};43exports.buildAddCardXML = function (card, mpAuth, xmlOptions) {44 var data = {};45 data.verification = mpAuth;46 data.command = 'add-card-onfile';47 // fixing month length48 card.expirationMonth = ('00' + card.expirationMonth).slice(-2);49 data.request = utils.formatObject(card, models.addCard);50 return xmlBuilder(xmlOptions).buildObject({51 'api-request': data52 });53};54exports.buildDeleteCardXML = function (card, mpAuth, xmlOptions) {55 var data = {};56 data.verification = mpAuth;57 data.command = 'delete-card-onfile';58 data.request = utils.formatObject(card, models.deleteCard);59 return xmlBuilder(xmlOptions).buildObject({60 'api-request': data61 });62};63exports.buildAuthXML = function (auth, mpAPIVersion, mpAuth, xmlOptions) {64 var data = {};65 data.version = mpAPIVersion;66 data.verification = mpAuth;67 data.order = {68 auth: utils.formatObject(auth, models.sale)69 };70 return xmlBuilder(xmlOptions).buildObject({71 'transaction-request': data72 });73};74exports.buildCaptureXML = function (capture, mpAPIVersion, mpAuth, xmlOptions) {75 var data = {};76 data.version = mpAPIVersion;77 data.verification = mpAuth;78 data.order = {79 capture: utils.formatObject(capture, models.capture)80 };81 return xmlBuilder(xmlOptions).buildObject({82 'transaction-request': data83 });84};85exports.buildVoidXML = function (_void, mpAPIVersion, mpAuth, xmlOptions) {86 var data = {};87 data.version = mpAPIVersion;88 data.verification = mpAuth;89 data.order = {90 void: utils.formatObject(_void, models.void)91 };92 return xmlBuilder(xmlOptions).buildObject({93 'transaction-request': data94 });95};96exports.buildSaleXML = function (sale, mpAPIVersion, mpAuth, xmlOptions) {97 xmlOptions.explicitArray = true;98 xmlOptions.attrNameProcessors = true;99 var data = {};100 data.version = mpAPIVersion;101 data.verification = mpAuth;102 data.order = {103 sale: sale //util.formatObject(sale, models.sale)104 };105 return xmlBuilder(xmlOptions).buildObject({106 'transaction-request': data107 });108};109exports.buildReturnPaymentXML = function (_return, mpAPIVersion, mpAuth, xmlOptions) {110 var data = {};111 data.version = mpAPIVersion;112 data.verification = mpAuth;113 data.order = {114 return: utils.formatObject(_return, models.returnPayment)115 };116 return xmlBuilder(xmlOptions).buildObject({117 'transaction-request': data118 });119};120exports.buildRecurringPaymentXML = function (recurringPayment, mpAPIVersion, mpAuth, xmlOptions) {121 var data = {};122 data.version = mpAPIVersion;123 data.verification = mpAuth;124 data.order = {125 recurringPayment: utils.formatObject(recurringPayment, models.recurringPayment)126 };127 return xmlBuilder(xmlOptions).buildObject({128 'transaction-request': data129 });130};131exports.buildUpdateRecurringPaymentXML = function (updateRecurringPayment, mpAuth, xmlOptions) {132 var data = {};133 data.verification = mpAuth;134 data.command = 'modify-recurring';135 data.request = utils.formatObject(updateRecurringPayment, models.updateRecurringPayment);136 return xmlBuilder(xmlOptions).buildObject({137 'api-request': data138 });139};140exports.buildCancelRecurringPaymentXML = function (cancelRecurringPayment, mpAuth, xmlOptions) {141 var data = {};142 data.verification = mpAuth;143 data.command = 'cancel-recurring';144 data.request = utils.formatObject(cancelRecurringPayment, models.updateRecurringPayment)145 return xmlBuilder(xmlOptions).buildObject({146 'api-request': data147 });148};149exports.buildTransactionQueryXML = function (transactionId, mpAuth, xmlOptions) {150 var data = {};151 data.verification = mpAuth;152 data.command = 'transactionDetailReport';153 data.request = utils.formatObject(transactionId, models.transactionQuery);154 return xmlBuilder(xmlOptions).buildObject({155 'rapi-request': data156 });...
currencyFormat.js
Source:currencyFormat.js
1'use strict';2/**3 * @description4 * Provides asynchronous GET requests for currency configuration files, fetched 5 * configurations are cached and served directly to subsequent requests.6 *7 * @returns {object} Wrapper object exposing request configuration method8 */9angular.module('bhima.services')10.factory('currencyFormat', ['$http', 'store', function ($http, Store) { 11 var currencyConfigurationPath = '/i18n/currency/';12 var loadedSupportedCurrencies = false;13 var supportedCurrencies = new Store({identifier : 'id'});14 var currentFormats = new Store({identifier : 'format_key'});15 var fetchingKeys = [];16 var invalidCurrency = { supported : false };17 18 // Request all defined BHIMA currencies19 $http.get('/finance/currencies')20 .success(function (currencyList) {21 supportedCurrencies.setData(currencyList);22 loadedSupportedCurrencies = true;23 });24 25 // Requests individual currency configurations26 function fetchFormatConfiguration(key) { 27 var formatObject = null;28 fetchingKeys[key] = true;29 30 $http.get(currencyConfigurationPath.concat(key, '.json'))31 .success(function (result) { 32 33 // Add configuration to local cache34 formatObject = result;35 formatObject.supported = true;36 formatObject.format_key = key;37 addFormat(formatObject); 38 })39 .catch(function (err) { 40 41 // Deny future attempts to request this configuration42 formatObject = invalidCurrency;43 formatObject.format_key = key;44 addFormat(formatObject);45 });46 }47 function addFormat(formatObject) { 48 // FIXME Resolve issue with initial Store data to just allow post. Github Ref: #49 if (angular.isUndefined(currentFormats.data.length)) { 50 currentFormats.setData([formatObject]);51 } else { 52 currentFormats.post(formatObject);53 }54 }55 56 /**57 * @param {number} currencyId ID of currency to be checked against BHIMA's database58 *59 * @returns {object} Returns format configuration if it has been found and fetched, 60 * objects reporting unsupported status if configuration or currency cannot be found61 */62 function searchFormatConfiguration(currencyId) {63 var supportedCurrency = supportedCurrencies.get(currencyId);64 if (angular.isUndefined(supportedCurrency)) { 65 return invalidCurrency;66 }67 68 // currency has been identified - search for configuration 69 var formatKey = supportedCurrency.format_key;70 var progress = fetchingKeys[formatKey];71 // initial for request for currency with this key - initialise configuration request72 if (!angular.isDefined(progress)) { 73 fetchFormatConfiguration(formatKey);74 }75 76 return currentFormats.get(formatKey);77 }78 79 /**80 * @returns {boolean} Exposes status of initial currency index cache request81 */82 function reportStatus() { 83 return loadedSupportedCurrencies;84 }85 return { 86 request : searchFormatConfiguration,87 indexReady : reportStatus88 };...
utils.js
Source:utils.js
...14 var formatted = {};15 Object.keys(reference).forEach(function(key) {16 if (object.hasOwnProperty(key)) {17 if (object[key] instanceof Object) {18 formatted[key] = formatObject(object[key], reference[key]);19 } else {20 formatted[key] = object[key];21 }22 }23 });24 return formatted;25};26exports.formatObject = formatObject;27exports.buildAddCustomerXML = function(customer, mpAuth, xmlOptions) {28 var data = {};29 data.verification = mpAuth;30 data.command = 'add-consumer';31 data.request = this.formatObject(customer, models.addCustomer);32 return xmlBuilder(xmlOptions).buildObject({33 'api-request': data34 });35};36exports.buildUpdateCustomerXML = function(customer, mpAuth, xmlOptions) {37 var data = {};38 data.verification = mpAuth;39 data.command = 'update-consumer';40 data.request = this.formatObject(customer, models.updateCustomer);41 return xmlBuilder(xmlOptions).buildObject({42 'api-request': data43 });44};45exports.buildSaleXML = function(sale, mpAPIVersion, mpAuth, xmlOptions) {46 var data = {};47 data.version = mpAPIVersion;48 data.verification = mpAuth;49 data.order = {50 sale: this.formatObject(sale, models.sale)51 };52 return xmlBuilder(xmlOptions).buildObject({53 'transaction-request': data54 });55};56exports.buildAddCardXML = function(card, mpAuth, xmlOptions) {57 var data = {};58 data.verification = mpAuth;59 data.command = 'add-card-onfile';60 // fixing month length61 card.expirationMonth = ('00' + card.expirationMonth).slice(-2);62 data.request = this.formatObject(card, models.addCard);63 return xmlBuilder(xmlOptions).buildObject({64 'api-request': data65 });66};67exports.buildDeleteCardXML = function(card, mpAuth, xmlOptions) {68 var data = {};69 data.verification = mpAuth;70 data.command = 'delete-card-onfile';71 data.request = this.formatObject(card, models.deleteCard);72 return xmlBuilder(xmlOptions).buildObject({73 'api-request': data74 });...
format.js
Source:format.js
1"use strict";23function formatObject(obj, formatObject, options) {4 formatObject = formatObject || options.format;56 let format = formatObject;7 let destination = (formatObject ? formatObject.destination : undefined) || "markdown";8 let parts = (options.partsByDestination ? options.partsByDestination[destination] : options.parts);910 if (typeof formatObject === "object") {11 format = formatObject.format;12 }13 else if (formatObject && (typeof formatObject !== "string")) {14 throw new Error("Format must be supplied as object or string.");15 }1617 format = format || (options.formatsByDestination ? options.formatsByDestination[destination] : undefined);
...
Using AI Code Generation
1const { formatObject } = require('playwright/lib/server/utils');2const obj = { a: 1, b: 2 };3const { formatObject } = require('playwright/lib/server/utils');4const obj = { a: 1, b: 2 };5const { formatObject } = require('playwright/lib/server/utils');6const obj = { a: 1, b: 2 };7const { formatObject } = require('playwright/lib/server/utils');8const obj = { a: 1, b: 2 };9const { formatObject } = require('playwright/lib/server/utils');10const obj = { a: 1, b: 2 };11const { formatObject } = require('playwright/lib/server/utils');12const obj = { a: 1, b: 2 };13const { formatObject } = require('playwright/lib/server/utils');14const obj = { a: 1, b: 2 };15const { formatObject } = require('playwright/lib/server/utils');16const obj = { a: 1, b: 2 };
Using AI Code Generation
1const { formatObject } = require('playwright/lib/utils/utils');2console.log(formatObject({ a: 1, b: 2, c: 3 }));3const { getExceptionMessage } = require('playwright/lib/utils/utils');4console.log(getExceptionMessage(new Error('error message')));5const { isString } = require('playwright/lib/utils/utils');6console.log(isString('test'));7const { isRegExp } = require('playwright/lib/utils/utils');8console.log(isRegExp(/test/));9const { isPrimitive } = require('playwright/lib/utils/utils');10console.log(isPrimitive('test'));
Using AI Code Generation
1const { formatObject } = require('playwright/lib/utils/stackTrace');2const obj = {a:1,b:2,c:3};3console.log(formatObject(obj));4const { formatError } = require('playwright/lib/utils/stackTrace');5const err = new Error('Error Message');6console.log(formatError(err));7const { rewriteErrorMessage } = require('playwright/lib/utils/stackTrace');8const err = new Error('Error Message');9console.log(rewriteErrorMessage(err, 'New Error Message'));10const { stackTraceWithSourceMaps } = require('playwright/lib/utils/stackTrace');11const err = new Error('Error Message');12console.log(stackTraceWithSourceMaps(err));13const { parseStackTrace } = require('playwright/lib/utils/stackTrace');14const err = new Error('Error Message');15console.log(parseStackTrace(err));16const { parseError } = require('playwright/lib/utils/stackTrace');17const err = new Error('Error Message');18console.log(parseError(err));19const { getCallerFile } = require('playwright/lib/utils/stackTrace');20console.log(getCallerFile());21const { installSourceMapSupport } = require('playwright/lib/utils/stackTrace');22console.log(installSourceMapSupport());23const { createGuid } = require('playwright/lib/utils/utils');24console.log(createGuid());
Using AI Code Generation
1const { formatObject } = require('playwright/lib/utils/stackTrace');2const obj = {3 {4 },5};6console.log(formatObject(obj));7{8 {9 },10}
Using AI Code Generation
1const { formatObject } = require('playwright/lib/utils/stackTrace');2const obj = {a:1,b:2,c:3};3console.log(formatObject(obj));4const { formatError } = require('playwright/lib/utils/stackTrace');5const err = new Error('Error Message');6console.log(formatError(err));7const { rewriteErrorMessage } = require('playwright/lib/utils/stackTrace');8const err = new Error('Error Message');9console.log(rewriteErrorMessage(e
Using AI Code Generation
1const { formatObject } = require('playwright/lib/utils/stackTrace');2const obj = { a: { b: { c: 'hello' } } };3console.log(formatObject(obj));4{ a: { b: { c: 'hello' } } }5[Apache 2.0](./LICENSE)rr, 'New Error Message'));6const { stackTraceWithSourceMaps } = require('playwright/lib/utils/stackTrace');7const err = new Error('Error Message');8console.log(stackTraceWithSourceMaps(err));9const { parseStackTrace } = require('playwright/lib/utils/stackTrace');10const err = new Error('Error Message');11console.log(parseStackTrace(err));12const { parseError } = require('playwright/lib/utils/stackTrace');13const err = new Error('Error Message');14console.log(parseError(err));15const { getCallerFile } = require('playwright/lib/utils/stackTrace');16console.log(getCallerFile());17const { installSourceMapSupport } = require('playwright/lib/utils/stackTrace');18console.log(installSourceMapSupport());19const { createGuid } = require('playwright/lib/utils/utils');20console.log(createGuid());
Using AI Code Generation
1const { formatObject } = require('playwright/lib/utils/stackTrace');2const obj = {3 {4 },5};6console.log(formatObject(obj));7{8 {9 },10}
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.
Get 100 minutes of automation test minutes FREE!!