Best JavaScript code snippet using storybook-root
index.js
Source:index.js
1import macro from 'vtk.js/Sources/macro';2import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';3import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray';4import vtkPoints from 'vtk.js/Sources/Common/Core/Points';5// ----------------------------------------------------------------------------6// vtkCursor3D methods7// ----------------------------------------------------------------------------8function vtkCursor3D(publicAPI, model) {9 // Set our className10 model.classHierarchy.push('vtkCursor3D');11 // Public API methods12 publicAPI.setModelBounds = (bounds) => {13 if (!Array.isArray(bounds) || bounds.length < 6) {14 return;15 }16 if (17 model.modelBounds[0] === bounds[0] &&18 model.modelBounds[1] === bounds[1] &&19 model.modelBounds[2] === bounds[2] &&20 model.modelBounds[3] === bounds[3] &&21 model.modelBounds[4] === bounds[4] &&22 model.modelBounds[5] === bounds[5]23 ) {24 return;25 }26 publicAPI.modified();27 // Doing type convert, make sure it is a number array.28 // Without correct coversion, the array may contains string which cause29 // the wrapping and clampping works incorrectly.30 model.modelBounds = bounds.map((v) => Number(v));31 for (let i = 0; i < 3; ++i) {32 model.modelBounds[2 * i] = Math.min(33 model.modelBounds[2 * i],34 model.modelBounds[2 * i + 1]35 );36 }37 };38 publicAPI.setFocalPoint = (points) => {39 if (!Array.isArray(points) || points.length < 3) {40 return;41 }42 if (43 points[0] === model.focalPoint[0] &&44 points[1] === model.focalPoint[1] &&45 points[2] === model.focalPoint[2]46 ) {47 return;48 }49 publicAPI.modified();50 const v = [];51 for (let i = 0; i < 3; i++) {52 v[i] = points[i] - model.focalPoint[i];53 model.focalPoint[i] = Number(points[i]);54 if (model.translationMode) {55 model.modelBounds[2 * i] += v[i];56 model.modelBounds[2 * i + 1] += v[i];57 }58 // wrap59 else if (model.wrap) {60 model.focalPoint[i] =61 model.modelBounds[2 * i] +62 (((model.focalPoint[i] - model.modelBounds[2 * i]) * 1.0) %63 ((model.modelBounds[2 * i + 1] - model.modelBounds[2 * i]) * 1.0));64 }65 // clamp66 else {67 if (points[i] < model.modelBounds[2 * i]) {68 model.focalPoint[i] = model.modelBounds[2 * i];69 }70 if (points[i] > model.modelBounds[2 * i + 1]) {71 model.focalPoint[i] = model.modelBounds[2 * i + 1];72 }73 }74 }75 };76 publicAPI.setAll = (flag) => {77 publicAPI.setOutline(flag);78 publicAPI.setAxes(flag);79 publicAPI.setXShadows(flag);80 publicAPI.setYShadows(flag);81 publicAPI.setZShadows(flag);82 };83 publicAPI.allOn = () => {84 publicAPI.setAll(true);85 };86 publicAPI.allOff = () => {87 publicAPI.setAll(false);88 };89 publicAPI.requestData = (inData, outData) => {90 if (model.deleted) {91 return;92 }93 let numPts = 0;94 let numLines = 0;95 // Check bounding box and origin96 if (model.wrap) {97 for (let i = 0; i < model.focalPoint.length; ++i) {98 model.focalPoint[i] =99 model.modelBounds[2 * i] +100 (((model.focalPoint[i] - model.modelBounds[2 * i]) * 1.0) %101 (model.modelBounds[2 * i + 1] - model.modelBounds[2 * i]));102 }103 } else {104 for (let i = 0; i < model.focalPoint.length; ++i) {105 model.focalPoint[i] = Math.max(106 model.focalPoint[i],107 model.modelBounds[2 * i]108 );109 model.focalPoint[i] = Math.min(110 model.focalPoint[i],111 model.modelBounds[2 * i + 1]112 );113 }114 }115 // allocate storage116 if (model.axes) {117 numPts += 6;118 numLines += 3;119 }120 if (model.outline) {121 numPts += 8;122 numLines += 12;123 }124 if (model.xShadows) {125 numPts += 8;126 numLines += 4;127 }128 if (model.yShadows) {129 numPts += 8;130 numLines += 4;131 }132 if (model.zShadows) {133 numPts += 8;134 numLines += 4;135 }136 if (numPts === 0) {137 return;138 }139 const polyData = vtkPolyData.newInstance();140 const newPts = vtkPoints.newInstance({ size: numPts * 3 });141 // vtkCellArray is a supporting object that explicitly represents cell142 // connectivity. The cell array structure is a raw integer list143 // of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...)144 // where n is the number of points in the cell, and id is a zero-offset index145 // into an associated point list.146 const newLines = vtkCellArray.newInstance({ size: numLines * (2 + 1) });147 let pid = 0;148 let cid = 0;149 // Create axes150 if (model.axes) {151 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];152 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];153 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];154 ++pid;155 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];156 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];157 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];158 ++pid;159 newLines.getData()[cid * 3 + 0] = 2;160 newLines.getData()[cid * 3 + 1] = pid - 2;161 newLines.getData()[cid * 3 + 2] = pid - 1;162 ++cid;163 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];164 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];165 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];166 ++pid;167 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];168 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];169 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];170 ++pid;171 newLines.getData()[cid * 3 + 0] = 2;172 newLines.getData()[cid * 3 + 1] = pid - 2;173 newLines.getData()[cid * 3 + 2] = pid - 1;174 ++cid;175 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];176 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];177 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];178 ++pid;179 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];180 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];181 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];182 ++pid;183 newLines.getData()[cid * 3 + 0] = 2;184 newLines.getData()[cid * 3 + 1] = pid - 2;185 newLines.getData()[cid * 3 + 2] = pid - 1;186 ++cid;187 }188 // create outline189 if (model.outline) {190 // first traid191 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];192 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];193 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];194 const corner024 = pid;195 ++pid;196 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];197 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];198 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];199 const corner124 = pid;200 ++pid;201 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];202 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];203 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];204 const corner034 = pid;205 ++pid;206 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];207 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];208 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];209 const corner025 = pid;210 ++pid;211 newLines.getData()[(cid + 0) * 3 + 0] = 2;212 newLines.getData()[(cid + 0) * 3 + 1] = corner024;213 newLines.getData()[(cid + 0) * 3 + 2] = corner124;214 newLines.getData()[(cid + 1) * 3 + 0] = 2;215 newLines.getData()[(cid + 1) * 3 + 1] = corner024;216 newLines.getData()[(cid + 1) * 3 + 2] = corner034;217 newLines.getData()[(cid + 2) * 3 + 0] = 2;218 newLines.getData()[(cid + 2) * 3 + 1] = corner024;219 newLines.getData()[(cid + 2) * 3 + 2] = corner025;220 cid += 3;221 // second triad222 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];223 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];224 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];225 const corner135 = pid;226 ++pid;227 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];228 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];229 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];230 const corner035 = pid;231 ++pid;232 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];233 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];234 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];235 const corner125 = pid;236 ++pid;237 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];238 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];239 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];240 const corner134 = pid;241 ++pid;242 newLines.getData()[(cid + 0) * 3 + 0] = 2;243 newLines.getData()[(cid + 0) * 3 + 1] = corner135;244 newLines.getData()[(cid + 0) * 3 + 2] = corner035;245 newLines.getData()[(cid + 1) * 3 + 0] = 2;246 newLines.getData()[(cid + 1) * 3 + 1] = corner135;247 newLines.getData()[(cid + 1) * 3 + 2] = corner125;248 newLines.getData()[(cid + 2) * 3 + 0] = 2;249 newLines.getData()[(cid + 2) * 3 + 1] = corner135;250 newLines.getData()[(cid + 2) * 3 + 2] = corner134;251 cid += 3;252 // Fill in remaining lines253 // vtk.js do not support checking repeating insertion254 newLines.getData()[(cid + 0) * 3 + 0] = 2;255 newLines.getData()[(cid + 0) * 3 + 1] = corner124;256 newLines.getData()[(cid + 0) * 3 + 2] = corner134;257 newLines.getData()[(cid + 1) * 3 + 0] = 2;258 newLines.getData()[(cid + 1) * 3 + 1] = corner124;259 newLines.getData()[(cid + 1) * 3 + 2] = corner125;260 cid += 2;261 newLines.getData()[(cid + 0) * 3 + 0] = 2;262 newLines.getData()[(cid + 0) * 3 + 1] = corner034;263 newLines.getData()[(cid + 0) * 3 + 2] = corner134;264 newLines.getData()[(cid + 1) * 3 + 0] = 2;265 newLines.getData()[(cid + 1) * 3 + 1] = corner034;266 newLines.getData()[(cid + 1) * 3 + 2] = corner035;267 cid += 2;268 newLines.getData()[(cid + 0) * 3 + 0] = 2;269 newLines.getData()[(cid + 0) * 3 + 1] = corner025;270 newLines.getData()[(cid + 0) * 3 + 2] = corner125;271 newLines.getData()[(cid + 1) * 3 + 0] = 2;272 newLines.getData()[(cid + 1) * 3 + 1] = corner025;273 newLines.getData()[(cid + 1) * 3 + 2] = corner035;274 cid += 2;275 }276 // create x-shadows277 if (model.xShadows) {278 for (let i = 0; i < 2; ++i) {279 newPts.getData()[pid * 3 + 0] = model.modelBounds[i];280 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];281 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];282 ++pid;283 newPts.getData()[pid * 3 + 0] = model.modelBounds[i];284 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];285 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];286 ++pid;287 newLines.getData()[cid * 3 + 0] = 2;288 newLines.getData()[cid * 3 + 1] = pid - 2;289 newLines.getData()[cid * 3 + 2] = pid - 1;290 ++cid;291 newPts.getData()[pid * 3 + 0] = model.modelBounds[i];292 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];293 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];294 ++pid;295 newPts.getData()[pid * 3 + 0] = model.modelBounds[i];296 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];297 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];298 ++pid;299 newLines.getData()[cid * 3 + 0] = 2;300 newLines.getData()[cid * 3 + 1] = pid - 2;301 newLines.getData()[cid * 3 + 2] = pid - 1;302 ++cid;303 }304 }305 // create y-shadows306 if (model.yShadows) {307 for (let i = 0; i < 2; ++i) {308 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];309 newPts.getData()[pid * 3 + 1] = model.modelBounds[i + 2];310 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];311 ++pid;312 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];313 newPts.getData()[pid * 3 + 1] = model.modelBounds[i + 2];314 newPts.getData()[pid * 3 + 2] = model.focalPoint[2];315 ++pid;316 newLines.getData()[cid * 3 + 0] = 2;317 newLines.getData()[cid * 3 + 1] = pid - 2;318 newLines.getData()[cid * 3 + 2] = pid - 1;319 ++cid;320 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];321 newPts.getData()[pid * 3 + 1] = model.modelBounds[i + 2];322 newPts.getData()[pid * 3 + 2] = model.modelBounds[4];323 ++pid;324 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];325 newPts.getData()[pid * 3 + 1] = model.modelBounds[i + 2];326 newPts.getData()[pid * 3 + 2] = model.modelBounds[5];327 ++pid;328 newLines.getData()[cid * 3 + 0] = 2;329 newLines.getData()[cid * 3 + 1] = pid - 2;330 newLines.getData()[cid * 3 + 2] = pid - 1;331 ++cid;332 }333 }334 // create z-shadows335 if (model.zShadows) {336 for (let i = 0; i < 2; ++i) {337 newPts.getData()[pid * 3 + 0] = model.modelBounds[0];338 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];339 newPts.getData()[pid * 3 + 2] = model.modelBounds[i + 4];340 ++pid;341 newPts.getData()[pid * 3 + 0] = model.modelBounds[1];342 newPts.getData()[pid * 3 + 1] = model.focalPoint[1];343 newPts.getData()[pid * 3 + 2] = model.modelBounds[i + 4];344 ++pid;345 newLines.getData()[cid * 3 + 0] = 2;346 newLines.getData()[cid * 3 + 1] = pid - 2;347 newLines.getData()[cid * 3 + 2] = pid - 1;348 ++cid;349 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];350 newPts.getData()[pid * 3 + 1] = model.modelBounds[2];351 newPts.getData()[pid * 3 + 2] = model.modelBounds[i + 4];352 ++pid;353 newPts.getData()[pid * 3 + 0] = model.focalPoint[0];354 newPts.getData()[pid * 3 + 1] = model.modelBounds[3];355 newPts.getData()[pid * 3 + 2] = model.modelBounds[i + 4];356 ++pid;357 newLines.getData()[cid * 3 + 0] = 2;358 newLines.getData()[cid * 3 + 1] = pid - 2;359 newLines.getData()[cid * 3 + 2] = pid - 1;360 ++cid;361 }362 }363 const pts = vtkPoints.newInstance({ size: 3 });364 pts.getData()[0] = model.focalPoint[0];365 pts.getData()[1] = model.focalPoint[1];366 pts.getData()[2] = model.focalPoint[2];367 // update ourseleves368 model.focus = vtkPolyData.newInstance();369 model.focus.setPoints(pts);370 polyData.setPoints(newPts);371 polyData.setLines(newLines);372 outData[0] = polyData;373 };374}375// ----------------------------------------------------------------------------376// Object factory377// ----------------------------------------------------------------------------378const DEFAULT_VALUES = {379 focus: null,380 modelBounds: [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0],381 focalPoint: [0.0, 0.0, 0.0],382 outline: true,383 axes: true,384 xShadows: true,385 yShadows: true,386 zShadows: true,387 wrap: false,388 translationMode: false,389};390// ----------------------------------------------------------------------------391export function extend(publicAPI, model, initialValues = {}) {392 Object.assign(model, DEFAULT_VALUES, initialValues);393 // Build VTK API394 // Cursor3D395 macro.obj(publicAPI, model);396 macro.get(publicAPI, model, ['focus']);397 macro.getArray(publicAPI, model, ['modelBounds'], 6);398 macro.getArray(publicAPI, model, ['focalPoint'], 3);399 macro.setGet(publicAPI, model, ['outline']);400 macro.setGet(publicAPI, model, ['axes']);401 macro.setGet(publicAPI, model, ['xShadows']);402 macro.setGet(publicAPI, model, ['yShadows']);403 macro.setGet(publicAPI, model, ['zShadows']);404 macro.setGet(publicAPI, model, ['wrap']);405 macro.setGet(publicAPI, model, ['translationMode']);406 macro.algo(publicAPI, model, 0, 1);407 vtkCursor3D(publicAPI, model);408}409// ----------------------------------------------------------------------------410export const newInstance = macro.newInstance(extend, 'vtkCursor3D');411// ----------------------------------------------------------------------------...
ext-beautify.js
Source:ext-beautify.js
1define("ace/ext/beautify/php_rules",["require","exports","module","ace/token_iterator"], function(require, exports, module) {2"use strict";3var TokenIterator = require("ace/token_iterator").TokenIterator;4exports.newLines = [{5 type: 'support.php_tag',6 value: '<?php'7}, {8 type: 'support.php_tag',9 value: '<?'10}, {11 type: 'support.php_tag',12 value: '?>'13}, {14 type: 'paren.lparen',15 value: '{',16 indent: true17}, {18 type: 'paren.rparen',19 breakBefore: true,20 value: '}',21 indent: false22}, {23 type: 'paren.rparen',24 breakBefore: true,25 value: '})',26 indent: false,27 dontBreak: true28}, {29 type: 'comment'30}, {31 type: 'text',32 value: ';'33}, {34 type: 'text',35 value: ':',36 context: 'php'37}, {38 type: 'keyword',39 value: 'case',40 indent: true,41 dontBreak: true42}, {43 type: 'keyword',44 value: 'default',45 indent: true,46 dontBreak: true47}, {48 type: 'keyword',49 value: 'break',50 indent: false,51 dontBreak: true52}, {53 type: 'punctuation.doctype.end',54 value: '>'55}, {56 type: 'meta.tag.punctuation.end',57 value: '>'58}, {59 type: 'meta.tag.punctuation.begin',60 value: '<',61 blockTag: true,62 indent: true,63 dontBreak: true64}, {65 type: 'meta.tag.punctuation.begin',66 value: '</',67 indent: false,68 breakBefore: true,69 dontBreak: true70}, {71 type: 'punctuation.operator',72 value: ';'73}];74exports.spaces = [{75 type: 'xml-pe',76 prepend: true77},{78 type: 'entity.other.attribute-name',79 prepend: true80}, {81 type: 'storage.type',82 value: 'var',83 append: true84}, {85 type: 'storage.type',86 value: 'function',87 append: true88}, {89 type: 'keyword.operator',90 value: '='91}, {92 type: 'keyword',93 value: 'as',94 prepend: true,95 append: true96}, {97 type: 'keyword',98 value: 'function',99 append: true100}, {101 type: 'support.function',102 next: /[^\(]/,103 append: true104}, {105 type: 'keyword',106 value: 'or',107 append: true,108 prepend: true109}, {110 type: 'keyword',111 value: 'and',112 append: true,113 prepend: true114}, {115 type: 'keyword',116 value: 'case',117 append: true118}, {119 type: 'keyword.operator',120 value: '||',121 append: true,122 prepend: true123}, {124 type: 'keyword.operator',125 value: '&&',126 append: true,127 prepend: true128}];129exports.singleTags = ['!doctype','area','base','br','hr','input','img','link','meta'];130exports.transform = function(iterator, maxPos, context) {131 var token = iterator.getCurrentToken();132 133 var newLines = exports.newLines;134 var spaces = exports.spaces;135 var singleTags = exports.singleTags;136 var code = '';137 138 var indentation = 0;139 var dontBreak = false;140 var tag;141 var lastTag;142 var lastToken = {};143 var nextTag;144 var nextToken = {};145 var breakAdded = false;146 var value = '';147 while (token!==null) {148 console.log(token);149 if( !token ){150 token = iterator.stepForward();151 continue;152 }153 if( token.type == 'support.php_tag' && token.value != '?>' ){154 context = 'php';155 }156 else if( token.type == 'support.php_tag' && token.value == '?>' ){157 context = 'html';158 }159 else if( token.type == 'meta.tag.name.style' && context != 'css' ){160 context = 'css';161 }162 else if( token.type == 'meta.tag.name.style' && context == 'css' ){163 context = 'html';164 }165 else if( token.type == 'meta.tag.name.script' && context != 'js' ){166 context = 'js';167 }168 else if( token.type == 'meta.tag.name.script' && context == 'js' ){169 context = 'html';170 }171 nextToken = iterator.stepForward();172 if (nextToken && nextToken.type.indexOf('meta.tag.name') == 0) {173 nextTag = nextToken.value;174 }175 if ( lastToken.type == 'support.php_tag' && lastToken.value == '<?=') {176 dontBreak = true;177 }178 if (token.type == 'meta.tag.name') {179 token.value = token.value.toLowerCase();180 }181 if (token.type == 'text') {182 token.value = token.value.trim();183 }184 if (!token.value) {185 token = nextToken;186 continue;187 }188 value = token.value;189 for (var i in spaces) {190 if (191 token.type == spaces[i].type &&192 (!spaces[i].value || token.value == spaces[i].value) &&193 (194 nextToken &&195 (!spaces[i].next || spaces[i].next.test(nextToken.value))196 )197 ) {198 if (spaces[i].prepend) {199 value = ' ' + token.value;200 }201 if (spaces[i].append) {202 value += ' ';203 }204 }205 }206 if (token.type.indexOf('meta.tag.name') == 0) {207 tag = token.value;208 }209 breakAdded = false;210 for (i in newLines) {211 if (212 token.type == newLines[i].type &&213 (214 !newLines[i].value ||215 token.value == newLines[i].value216 ) &&217 (218 !newLines[i].blockTag ||219 singleTags.indexOf(nextTag) === -1220 ) &&221 (222 !newLines[i].context ||223 newLines[i].context === context224 )225 ) {226 if (newLines[i].indent === false) {227 indentation--;228 }229 if (230 newLines[i].breakBefore &&231 ( !newLines[i].prev || newLines[i].prev.test(lastToken.value) )232 ) {233 code += "\n";234 breakAdded = true;235 for (i = 0; i < indentation; i++) {236 code += "\t";237 }238 }239 break;240 }241 }242 if (dontBreak===false) {243 for (i in newLines) {244 if (245 lastToken.type == newLines[i].type &&246 (247 !newLines[i].value || lastToken.value == newLines[i].value248 ) &&249 (250 !newLines[i].blockTag ||251 singleTags.indexOf(tag) === -1252 ) &&253 (254 !newLines[i].context ||255 newLines[i].context === context256 )257 ) {258 if (newLines[i].indent === true) {259 indentation++;260 }261 if (!newLines[i].dontBreak && !breakAdded) {262 code += "\n";263 for (i = 0; i < indentation; i++) {264 code += "\t";265 }266 }267 break;268 }269 }270 }271 code += value;272 if ( lastToken.type == 'support.php_tag' && lastToken.value == '?>' ) {273 dontBreak = false;274 }275 lastTag = tag;276 lastToken = token;277 token = nextToken;278 if (token===null) {279 break;280 }281 }282 283 return code;284};285});286define("ace/ext/beautify",["require","exports","module","ace/token_iterator","ace/ext/beautify/php_rules"], function(require, exports, module) {287"use strict";288var TokenIterator = require("ace/token_iterator").TokenIterator;289var phpTransform = require("./beautify/php_rules").transform;290exports.beautify = function(session) {291 var iterator = new TokenIterator(session, 0, 0);292 var token = iterator.getCurrentToken();293 var context = session.$modeId.split("/").pop();294 var code = phpTransform(iterator, context);295 session.doc.setValue(code);296};297exports.commands = [{298 name: "beautify",299 exec: function(editor) {300 exports.beautify(editor.session);301 },302 bindKey: "Ctrl-Shift-B"303}]304});305 (function() {306 window.require(["ace/ext/beautify"], function() {});307 })();...
newlines.js
Source:newlines.js
1// Copyright 2013 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Utilities for string newlines.16 * @author nnaze@google.com (Nathan Naze)17 */18/**19 * Namespace for string utilities20 */21goog.provide('goog.string.newlines');22goog.provide('goog.string.newlines.Line');23goog.require('goog.array');24/**25 * Splits a string into lines, properly handling universal newlines.26 * @param {string} str String to split.27 * @param {boolean=} opt_keepNewlines Whether to keep the newlines in the28 * resulting strings. Defaults to false.29 * @return {!Array.<string>} String split into lines.30 */31goog.string.newlines.splitLines = function(str, opt_keepNewlines) {32 var lines = goog.string.newlines.getLines(str);33 return goog.array.map(lines, function(line) {34 return opt_keepNewlines ? line.getFullLine() : line.getContent();35 });36};37/**38 * Line metadata class that records the start/end indicies of lines39 * in a string. Can be used to implement common newline use cases such as40 * splitLines() or determining line/column of an index in a string.41 * Also implements methods to get line contents.42 *43 * Indexes are expressed as string indicies into string.substring(), inclusive44 * at the start, exclusive at the end.45 *46 * Create an array of these with goog.string.newlines.getLines().47 * @param {string} string The original string.48 * @param {number} startLineIndex The index of the start of the line.49 * @param {number} endContentIndex The index of the end of the line, excluding50 * newlines.51 * @param {number} endLineIndex The index of the end of the line, index52 * newlines.53 * @constructor54 * @struct55 */56goog.string.newlines.Line = function(string, startLineIndex,57 endContentIndex, endLineIndex) {58 /**59 * The original string.60 * @type {string}61 */62 this.string = string;63 /**64 * Index of the start of the line.65 * @type {number}66 */67 this.startLineIndex = startLineIndex;68 /**69 * Index of the end of the line, excluding any newline characters.70 * Index is the first character after the line, suitable for71 * String.substring().72 * @type {number}73 */74 this.endContentIndex = endContentIndex;75 /**76 * Index of the end of the line, excluding any newline characters.77 * Index is the first character after the line, suitable for78 * String.substring().79 * @type {number}80 */81 this.endLineIndex = endLineIndex;82};83/**84 * @return {string} The content of the line, excluding any newline characters.85 */86goog.string.newlines.Line.prototype.getContent = function() {87 return this.string.substring(this.startLineIndex, this.endContentIndex);88};89/**90 * @return {string} The full line, including any newline characters.91 */92goog.string.newlines.Line.prototype.getFullLine = function() {93 return this.string.substring(this.startLineIndex, this.endLineIndex);94};95/**96 * @return {string} The newline characters, if any ('\n', \r', '\r\n', '', etc).97 */98goog.string.newlines.Line.prototype.getNewline = function() {99 return this.string.substring(this.endContentIndex, this.endLineIndex);100};101/**102 * Splits a string into an array of line metadata.103 * @param {string} str String to split.104 * @return {!Array.<!goog.string.newlines.Line>} Array of line metadata.105 */106goog.string.newlines.getLines = function(str) {107 // We use the constructor because literals are evaluated only once in108 // < ES 3.1.109 // See http://www.mail-archive.com/es-discuss@mozilla.org/msg01796.html110 var re = RegExp('\r\n|\r|\n', 'g');111 var sliceIndex = 0;112 var result;113 var lines = [];114 while (result = re.exec(str)) {115 var line = new goog.string.newlines.Line(116 str, sliceIndex, result.index, result.index + result[0].length);117 lines.push(line);118 // remember where to start the slice from119 sliceIndex = re.lastIndex;120 }121 // If the string does not end with a newline, add the last line.122 if (sliceIndex < str.length) {123 var line = new goog.string.newlines.Line(124 str, sliceIndex, str.length, str.length);125 lines.push(line);126 }127 return lines;...
Using AI Code Generation
1var newLines = require('storybook-root').newLines;2console.log(newLines(3));3var newLines = require('storybook-root').newLines;4console.log(newLines(3));5var rootPath = require('storybook-root').rootPath;6console.log(rootPath);7var rootPath = require('storybook-root').rootPath;8console.log(rootPath);9var rootPath = require('storybook-root').rootPath;10console.log(rootPath);11var rootPath = require('storybook-root').rootPath;12console.log(rootPath);13var rootPath = require('storybook-root').rootPath;14console.log(rootPath);
Using AI Code Generation
1import { newLines } from 'storybook-root';2newLines(2);3import { newLines } from 'storybook-root';4newLines(1);5 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true6 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/config.js (webpack)-hot-middleware/client.js?reload=true7module.exports = require('./newLines');8alias: {9 'storybook-root': path.resolve(__dirname, '../')10}11 ["module-resolver", {12 "alias": {13 }14 }]15"compilerOptions": {16 "paths": {17 }18}19"compilerOptions": {20 "paths": {
Using AI Code Generation
1import { newLine } from 'storybook-root';2newLine();3import { newLine } from 'storybook-root';4newLine();5import { newLine } from 'storybook-root';6newLine();7import { newLine } from 'storybook-root';8newLine();9import { newLine } from 'storybook-root';10newLine();11import { newLine } from 'storybook-root';12newLine();13import { newLine } from 'storybook-root';14newLine();15import { newLine } from 'storybook-root';16newLine();17import { newLine } from 'storybook-root';18newLine();19import { newLine } from 'storybook-root';20newLine();21import { newLine } from 'storybook-root';22newLine();23import { newLine } from 'storybook-root';24newLine();25import { newLine } from 'storybook-root';26newLine();27import { newLine } from 'storybook-root';28newLine();29import { newLine } from 'storybook-root';30newLine();
Using AI Code Generation
1import { newLines } from 'storybook-root'2const lines = newLines(5)3import { newLines } from './newLines'4export { newLines }5export const newLines = (num) => {6 for (let i = 0; i < num; i++) {7 lines.push({ id: i + 1, text: `Line ${i + 1}` })8 }9}10import { newLines } from './newLines'11describe('newLines', () => {12 it('should return an array of objects with text and id', () => {13 const lines = newLines(5)14 expect(lines).toHaveLength(5)15 expect(lines[0]).toHaveProperty('text')16 expect(lines[0]).toHaveProperty('id')17 })18})19import { newLines } from './newLines'20export default {21}22export const Default = () => {23 const lines = newLines(5)24 return (25 {lines.map((line) => (26 <li key={line.id}>{line.text}</li>27 ))}28}29import { render } from '@testing-library/react'30import { Default } from './newLines.stories'31describe('newLines', () => {32 it('should render 5 lines', () => {33 const { getAllByRole } = render(<Default />)34 const listItems = getAllByRole('
Using AI Code Generation
1import logger from 'storybook-root-logger';2export default function test() {3 logger.newLines(3);4 logger.info('test');5}6import logger from 'storybook-root-logger';7logger.setConfig({
Using AI Code Generation
1const newLines = (num = 1) => {2 let str = "";3 for (let i = 0; i < num; i++) {4";5 }6 return str;7}8const newLines = (num = 1) => {9 let str = "";10 for (let i = 0; i < num; i++) {11";12 }13 return str;14}15const newLines = (num = 1) => {16 let str = "";17 for (let i = 0; i < num; i++) {18";19 }20 return str;21}22const newLines = (num = 1) => {23 let str = "";24 for (let i = 0; i < num; i++) {25";26 }27 return str;28}29const newLines = (num = 1) => {30 let str = "";31 for (let i = 0; i < num; i++) {32";33 }34 return str;35}36const newLines = (num = 1) => {37 let str = "";38 for (let i = 0; i < num; i++) {39";40 }41 return str;42}43const newLines = (num = 1
Using AI Code Generation
1import { newLines } from 'storybook-root';2newLines(10);3console.log(newLines(10));4import { newLines } from 'storybook-root';5newLines(10);6console.log(newLines(10));7import { newLines } from 'storybook-root';8newLines(10);9console.log(newLines(10));10import { newLines } from 'storybook-root';11newLines(10);12console.log(newLines(10));13import { newLines } from 'storybook-root';14newLines(10);15console.log(newLines(10));16import { newLines } from 'storybook-root';17newLines(10);18console.log(newLines(10));19import { newLines } from 'storybook-root';20newLines(10);21console.log(newLines(10));22import { newLines } from 'storybook-root';23newLines(10);24console.log(newLines(10));25import { newLines } from 'storybook-root';26newLines(10);27console.log(newLines(10));28import { newLines } from 'storybook-root';
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!