Best JavaScript code snippet using storybook-root
analyze.js
Source:analyze.js
1// accepts an array of objects with token and type attributes2function parse(tokens) {3 const parseObject = {4 currentIndex: 0,5 tokens: tokens,6 }7 const regexes = provideRegexes();8 return eatClass(parseObject, regexes);9}10/////////////////////// PROGRAM STRUCTURE ///////////////////////11function eatClass(parseObject, regexes) {12 const classString = eatKeyword(parseObject, regexes);13 const className = eatIdentifier(parseObject, regexes);14 const openBrace = eatSymbol(parseObject, regexes);15 const classVarDecs = eatClassVarDecs(parseObject, regexes);16 const subroutineDecs = eatSubroutineDecs(parseObject, regexes);17 const closeBrace = eatSymbol(parseObject, regexes);18 if (classString.token !== 'class' || openBrace.token !== '{' || closeBrace.token !== '}')19 throwError(parseObject);20 return {21 classString,22 className,23 openBrace,24 classVarDecs,25 subroutineDecs,26 closeBrace,27 };28}29function eatClassVarDecs(parseObject, regexes) {30 const beginningOfClassVarDec = /static|field/;31 const varDecs = [];32 while (beginningOfClassVarDec.test(currentToken(parseObject)))33 varDecs.push(eatClassVarDec(parseObject, regexes));34 return varDecs;35}36function eatClassVarDec(parseObject, regexes) {37 const mainVariableType = eatKeyword(parseObject, regexes);38 const type = eatType(parseObject, regexes);39 const varNames = eatVarNames(parseObject, regexes);40 const endSemicolon = eatSymbol(parseObject, regexes);41 if (!(mainVariableType.token === 'static' || mainVariableType.token === 'field') || endSemicolon.token !== ';')42 throwError(parseObject);43 return {44 mainVariableType,45 type,46 varNames,47 endSemicolon,48 }49}50function eatSubroutineDecs(parseObject, regexes) {51 const beginningOfSubroutineDec = /constructor|function|method/;52 const subroutineDecs = [];53 while (beginningOfSubroutineDec.test(currentToken(parseObject)))54 subroutineDecs.push(eatSubroutineDec(parseObject, regexes));55 return subroutineDecs;56}57function eatSubroutineDec(parseObject, regexes) {58 const mainSubroutineType = eatKeyword(parseObject, regexes);59 const subroutineType = eatSubroutineType(parseObject, regexes);60 const subroutineName = eatIdentifier(parseObject, regexes);61 const openParen = eatSymbol(parseObject, regexes);62 const paramaterList = eatParameterList(parseObject, regexes);63 const closeParen = eatSymbol(parseObject, regexes);64 const subroutineBody = eatSubroutineBody(parseObject, regexes);65 if (!(mainSubroutineType.token === 'constructor' || mainSubroutineType.token === 'function' || mainSubroutineType.token === 'method')66 || openParen.token !== '(' || closeParen.token !== ')')67 throwError(parseObject);68 return {69 mainSubroutineType,70 subroutineType,71 subroutineName,72 openParen,73 paramaterList,74 closeParen,75 subroutineBody,76 }77}78function eatSubroutineType(parseObject, regexes) {79 return /void|int|char|boolean/.test(currentToken(parseObject)) ?80 eatKeyword(parseObject, regexes) : eatIdentifier(parseObject, regexes);81}82function eatType(parseObject, regexes) {83 const tokenType = parseObject.tokens[parseObject.currentIndex].type;84 const type = tokenType === 'keyword' ?85 eatKeyword(parseObject, regexes) : eatIdentifier(parseObject, regexes);86 if (tokenType.token === 'keyword' && !(type.token === 'int' || type.token === 'char' || type.token === 'boolean'))87 throwError(parseObject);88 return type;89}90function eatVarNames(parseObject, regexes) {91 const varNames = [eatIdentifier(parseObject, regexes)];92 while(currentToken(parseObject) === ',') {93 varNames.push(eatSymbol(parseObject, regexes));94 varNames.push(eatIdentifier(parseObject, regexes));95 }96 return varNames;97}98function eatParameterList(parseObject, regexes) {99 const parameters = [];100 if (regexes.keywordRegex.test(currentToken(parseObject))) {101 parameters.push(eatType(parseObject, regexes));102 parameters.push(eatIdentifier(parseObject, regexes));103 while(currentToken(parseObject) === ',') {104 parameters.push(eatSymbol(parseObject, regexes));105 parameters.push(eatType(parseObject, regexes));106 parameters.push(eatIdentifier(parseObject, regexes));107 }108 }109 return parameters;110}111function eatSubroutineBody(parseObject, regexes) {112 const openBrace = eatSymbol(parseObject, regexes);113 const varDecs = eatVarDecs(parseObject, regexes);114 const statements = eatStatements(parseObject, regexes);115 const closeBrace = eatSymbol(parseObject, regexes);116 if (openBrace.token !== '{' || closeBrace.token !== '}') throwError(parseObject);117 return {118 openBrace,119 varDecs,120 statements,121 closeBrace,122 }123}124function eatVarDecs(parseObject, regexes) {125 const varDecs = [];126 while (currentToken(parseObject) === 'var')127 varDecs.push(eatVarDec(parseObject, regexes));128 return varDecs;129}130function eatVarDec(parseObject, regexes) {131 const varString = eatKeyword(parseObject, regexes);132 const type = eatType(parseObject, regexes);133 const varNames = [eatIdentifier(parseObject, regexes)];134 while (currentToken(parseObject) === ',') {135 varNames.push(eatSymbol(parseObject, regexes));136 varNames.push(eatIdentifier(parseObject, regexes));137 }138 const endSemicolon = eatSymbol(parseObject, regexes);139 if (varString.token !== 'var' || endSemicolon.token !== ';')140 throwError(parseObject);141 return {142 varString,143 type,144 varNames,145 endSemicolon,146 }147}148/////////////////////// STATEMENTS ///////////////////////149function eatStatements(parseObject, regexes) {150 const statements = [];151 while (/let|if|while|do|return/.test(currentToken(parseObject)))152 statements.push(eatStatement(parseObject, regexes));153 return statements;154}155function eatStatement(parseObject, regexes) {156 const currToken = currentToken(parseObject);157 return currToken === 'let' ? eatLetStatement(parseObject, regexes):158 currToken === 'if' ? eatIfStatement(parseObject, regexes):159 currToken === 'while' ? eatWhileStatement(parseObject, regexes):160 currToken === 'do' ? eatDoStatement(parseObject, regexes):161 eatReturnStatement(parseObject, regexes);162}163function eatLetStatement(parseObject, regexes) {164 const letString = eatKeyword(parseObject, regexes);165 const varName = eatIdentifier(parseObject, regexes);166 let openBracket, arrayIndex, closeBracket;167 if (currentToken(parseObject) === '[') {168 openBracket = eatSymbol(parseObject, regexes);169 arrayIndex = eatExpression(parseObject, regexes);170 closeBracket = eatSymbol(parseObject, regexes);171 if (closeBracket.token !== ']') throwError(parseObject);172 }173 const equalsSign = eatSymbol(parseObject, regexes);174 const expression = eatExpression(parseObject, regexes);175 const endSemicolon = eatSymbol(parseObject, regexes);176 if (equalsSign.token !== '=' || endSemicolon.token !== ';') throwError(parseObject);177 return openBracket ? {178 letString,179 varName,180 openBracket,181 arrayIndex,182 closeBracket,183 equalsSign,184 expression,185 endSemicolon,186 } : {187 letString,188 varName,189 equalsSign,190 expression,191 endSemicolon,192 };193}194function eatIfStatement(parseObject, regexes) {195 const ifString = eatKeyword(parseObject, regexes);196 const openParen = eatSymbol(parseObject, regexes);197 const expression = eatExpression(parseObject, regexes);198 const closeParen = eatSymbol(parseObject, regexes);199 const openBrace = eatSymbol(parseObject, regexes);200 const statements = eatStatements(parseObject, regexes);201 const closeBrace = eatSymbol(parseObject, regexes);202 const elseStatement = currentToken(parseObject) === 'else' ?203 eatElseStatement(parseObject, regexes) : null;204 return elseStatement ? {205 ifString,206 openParen,207 expression,208 closeParen,209 openBrace,210 statements,211 closeBrace,212 elseStatement,213 } : {214 ifString,215 openParen,216 expression,217 closeParen,218 openBrace,219 statements,220 closeBrace,221 };222}223function eatElseStatement(parseObject, regexes) {224 const elseString = eatKeyword(parseObject, regexes);225 const openBrace = eatSymbol(parseObject, regexes);226 const statements = eatStatements(parseObject, regexes);227 const closeBrace = eatSymbol(parseObject, regexes);228 if (openBrace.token !== '{' || closeBrace.token !== '}') throwError(parseObject);229 return {230 elseString,231 openBrace,232 statements,233 closeBrace,234 }235}236function eatWhileStatement(parseObject, regexes) {237 const whileString = eatKeyword(parseObject, regexes);238 const openParen = eatSymbol(parseObject, regexes);239 const expression = eatExpression(parseObject, regexes);240 const closeParen = eatSymbol(parseObject, regexes);241 const openBrace = eatSymbol(parseObject, regexes);242 const statements = eatStatements(parseObject, regexes);243 const closeBrace = eatSymbol(parseObject, regexes);244 if (openParen.token !== '(' || closeParen.token !== ')' || openBrace.token !== '{' || closeBrace.token !== '}')245 throwError(parseObject);246 return {247 whileString,248 openParen,249 expression,250 closeParen,251 openBrace,252 statements,253 closeBrace,254 };255}256function eatDoStatement(parseObject, regexes) {257 const doString = eatKeyword(parseObject, regexes);258 const subroutineCall = eatSubroutineCall(parseObject, regexes);259 const endSemicolon = eatSymbol(parseObject, regexes);260 if (endSemicolon.token !== ';') throwError(parseObject);261 return {262 doString,263 subroutineCall,264 endSemicolon,265 };266}267function eatReturnStatement(parseObject, regexes) {268 const returnString = eatKeyword(parseObject, regexes);269 const expression = currentToken(parseObject) === ';' ?270 null : eatExpression(parseObject, regexes);271 const endSemicolon = eatSymbol(parseObject, regexes);272 if (endSemicolon.token !== ';') throwError(parseObject);273 return expression ? {274 returnString,275 expression,276 endSemicolon,277 } : {278 returnString,279 endSemicolon,280 };281}282/////////////////////// EXPRESSIONS ///////////////////////283function eatExpression(parseObject, regexes) {284 const term = eatTerm(parseObject, regexes);285 const extraTerms = [];286 while (/\+|-|\*|\/|&|\||<|>|=/.test(currentToken(parseObject))) {287 extraTerms.push(eatOperation(parseObject, regexes));288 extraTerms.push(eatTerm(parseObject, regexes));289 }290 return extraTerms ? {291 term,292 extraTerms,293 } : term;294}295function eatTerm(parseObject, regexes) {296 let term;297 if (currentTokenType(parseObject) === 'integerConstant')298 term = eatIntegerConstant(parseObject, regexes);299 else if (currentTokenType(parseObject) === 'stringConstant')300 term = eatStringConstant(parseObject, regexes);301 else if (currentTokenType(parseObject) === 'keyword')302 term = eatKeyword(parseObject, regexes);303 // test if we have unaryOp term304 else if (/-|~/.test(currentToken(parseObject))) {305 const unaryOp = eatSymbol(parseObject, regexes);306 term = {307 unaryOp,308 term: eatTerm(parseObject, regexes),309 };310 }311 // test if we have the form varName[expression]312 else if (nextToken(parseObject) === '[') {313 const varName = eatIdentifier(parseObject, regexes);314 const openBracket = eatSymbol(parseObject, regexes);315 const expression = eatExpression(parseObject, regexes);316 const closeBracket = eatSymbol(parseObject, regexes);317 term = {318 varName,319 openBracket,320 expression,321 closeBracket,322 };323 }324 // test if we have (expression)325 else if (currentToken(parseObject) === '(') {326 const openParen = eatSymbol(parseObject, regexes);327 const expression = eatExpression(parseObject, regexes);328 const closeParen = eatSymbol(parseObject, regexes);329 term = {330 openParen,331 expression,332 closeParen,333 };334 }335 // test if we have subroutineCall336 else if (nextToken(parseObject) === '(' || nextToken(parseObject) === '.')337 term = eatSubroutineCall(parseObject, regexes);338 // if all the above fail, we must have varName339 else term = eatIdentifier(parseObject, regexes);340 return term;341}342function eatOperation(parseObject, regexes) {343 const operation = eatSymbol(parseObject, regexes);344 if (!/\+|-|\*|\/|&|\||<|>|=/.test(operation.token)) throwError(parseObject);345 return operation;346}347function eatUnaryOperation(parseObject, regexes) {348 const operation = eatSymbol(parseObject, regexes);349 if (!/-|~/.test(operation.token)) throwError(parseObject);350 return operation;351}352function eatKeywordConstant(parseObject, regexes) {353 const keyword = eatKeyword(parseObject, regexes);354 if (!/true|false|null|this/.test(keyword.token)) throwError(parseObject);355 return keyword;356}357function eatSubroutineCall(parseObject, regexes) {358 let subroutineCall;359 if (nextToken(parseObject) === '(') {360 const subroutineName = eatIdentifier(parseObject, regexes);361 const openParen = eatSymbol(parseObject, regexes);362 const expressionList = eatExpressionList(parseObject, regexes);363 const closeParen = eatSymbol(parseObject, regexes);364 subroutineCall = {365 subroutineName,366 openParen,367 expressionList,368 closeParen,369 };370 } else {371 const name = eatIdentifier(parseObject, regexes);372 const dot = eatSymbol(parseObject, regexes);373 const subroutineName = eatIdentifier(parseObject, regexes);374 const openParen = eatSymbol(parseObject, regexes);375 const expressionList = eatExpressionList(parseObject, regexes);376 const closeParen = eatSymbol(parseObject, regexes);377 subroutineCall = {378 name,379 dot,380 subroutineName,381 openParen,382 expressionList,383 closeParen,384 };385 }386 return subroutineCall;387}388function eatExpressionList(parseObject, regexes) {389 if (currentToken(parseObject) === ')') return null;390 const expression = eatExpression(parseObject, regexes);391 const expressions = [];392 while(currentToken(parseObject) === ',') {393 expressions.push(eatSymbol(parseObject, regexes));394 expressions.push(eatExpression(parseObject, regexes));395 }396 return expressions ? {397 expression,398 expressions,399 } : expression;400}401/////////////////////// LEXICAL ELEMENTS ///////////////////////402function eatKeyword(parseObject, regexes) {403 return eatTerminalToken(parseObject, regexes.keywordRegex)404}405function eatSymbol(parseObject, regexes) {406 return eatTerminalToken(parseObject, regexes.symbolRegex)407}408function eatIntegerConstant(parseObject, regexes) {409 return eatTerminalToken(parseObject, regexes.integerConstantRegex)410}411function eatStringConstant(parseObject, regexes) {412 return eatTerminalToken(parseObject, regexes.stringConstantRegex);413}414function eatIdentifier(parseObject, regexes) {415 return eatTerminalToken(parseObject, regexes.identifierRegex)416}417function eatTerminalToken(parseObject, regex) {418 if (regex.test(currentToken(parseObject)))419 return parseObject.tokens[parseObject.currentIndex++];420 else throwError(parseObject);421}422/////////////////////// HELPER FUNCTIONS ///////////////////////423function currentToken(parseObject) {424 return parseObject.tokens[parseObject.currentIndex].token;425}426function nextToken(parseObject) {427 return parseObject.tokens[parseObject.currentIndex + 1].token;428}429function currentTokenType(parseObject) {430 return parseObject.tokens[parseObject.currentIndex].type;431}432function throwError(parseObject) {433 console.log(parseObject.currentIndex);434 console.log(currentToken(parseObject), nextToken(parseObject));435 throw Error;...
JsYamlParser.spec.js
Source:JsYamlParser.spec.js
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19import {JsYamlParser, YamlParseNode} from './JsYamlParser'20describe('Extended js-yaml parser', function () {21 const TEST_YAML = '' +22 'scalar_key: scalar_value\n' +23 'mapping_key:\n' +24 ' 1: mapping_val1\n' +25 ' 2: mapping_val2\n' +26 ' 3: mapping_val3\n' +27 'sequence_key:\n' +28 '- sequence_val1\n' +29 '- sequence_val2\n' +30 '- sequence_val3\n' +31 'null_key:';32 var jsYamlParser;33 beforeEach(function () {34 jsYamlParser = new JsYamlParser();35 });36 afterEach(function () {37 });38 describe('parsing a YAML string', function () {39 var parseObject;40 beforeEach(function () {41 parseObject = jsYamlParser.parse(TEST_YAML);42 });43 describe("YamlParseNode Object", function () {44 it('should parse a yaml string to a YamlParseNode', function () {45 expect(parseObject).not.toBeNull();46 expect(parseObject instanceof YamlParseNode).toBe(true);47 expect(parseObject.result).not.toBeNull();48 expect(parseObject.doc).toBe(TEST_YAML);49 });50 it('should have the correct number of child nodes', function () {51 expect(parseObject.children.length).toBe(8);52 });53 it('should parse YAML scalars', function () {54 //TEST KEY55 expect(parseObject.children[0]['doc']).toBe(TEST_YAML);56 expect(parseObject.children[0]['kind']).toBe('scalar');57 expect(parseObject.children[0]['result']).toBe('scalar_key');58 expect(parseObject.children[0]['children']).toBeDefined();59 expect(parseObject.children[0]['children'] instanceof Array).toBe(true);60 expect(parseObject.children[0]['children'].length).toBe(0);61 expect(parseObject.children[0]['parent']).toBe(parseObject);62 //TEST VALUE63 expect(parseObject.children[1]['doc']).toBe(TEST_YAML);64 expect(parseObject.children[1]['kind']).toBe('scalar');65 expect(parseObject.children[1]['result']).toBe('scalar_value');66 expect(parseObject.children[1]['children']).toBeDefined();67 expect(parseObject.children[1]['children'] instanceof Array).toBe(true);68 expect(parseObject.children[1]['children'].length).toBe(0);69 expect(parseObject.children[0]['parent']).toBe(parseObject)70 });71 it('should parse YAML mappings', function () {72 //TEST KEY73 expect(parseObject.children[2]['doc']).toBe(TEST_YAML);74 expect(parseObject.children[2]['kind']).toBe('scalar');75 expect(parseObject.children[2]['result']).toBe('mapping_key');76 expect(parseObject.children[2]['children']).toBeDefined();77 expect(parseObject.children[2]['children'] instanceof Array).toBe(true);78 expect(parseObject.children[2]['children'].length).toBe(0);79 expect(parseObject.children[2]['parent']).toBe(parseObject);80 //TEST VALUE81 expect(parseObject.children[3]['doc']).toBe(TEST_YAML);82 expect(parseObject.children[3]['kind']).toBe('mapping');83 expect(parseObject.children[3]['result']).not.toBeNull()84 expect(parseObject.children[3]['children']).toBeDefined();85 expect(parseObject.children[3]['children'] instanceof Array).toBe(true);86 expect(parseObject.children[3]['children'].length).toBe(6);87 expect(parseObject.children[3]['parent']).toBe(parseObject)88 });89 it('should parse YAML sequence', function () {90 //TEST KEY91 expect(parseObject.children[4]['doc']).toBe(TEST_YAML);92 expect(parseObject.children[4]['kind']).toBe('scalar');93 expect(parseObject.children[4]['result']).toBe('sequence_key');94 expect(parseObject.children[4]['children']).toBeDefined();95 expect(parseObject.children[4]['children'] instanceof Array).toBe(true);96 expect(parseObject.children[4]['children'].length).toBe(0);97 expect(parseObject.children[4]['parent']).toBe(parseObject);98 //TEST VALUE99 expect(parseObject.children[5]['doc']).toBe(TEST_YAML);100 expect(parseObject.children[5]['kind']).toBe('sequence');101 expect(parseObject.children[5]['result']).not.toBeNull()102 expect(parseObject.children[5]['children']).toBeDefined();103 expect(parseObject.children[5]['children'] instanceof Array).toBe(true);104 expect(parseObject.children[5]['children'].length).toBe(3);105 expect(parseObject.children[5]['parent']).toBe(parseObject)106 });107 it('should parse YAML nulls', function () {108 //TEST KEY109 expect(parseObject.children[6]['doc']).toBe(TEST_YAML);110 expect(parseObject.children[6]['kind']).toBe('scalar');111 expect(parseObject.children[6]['result']).toBe('null_key');112 expect(parseObject.children[6]['children']).toBeDefined();113 expect(parseObject.children[6]['children'] instanceof Array).toBe(true);114 expect(parseObject.children[6]['children'].length).toBe(0);115 expect(parseObject.children[6]['parent']).toBe(parseObject);116 //TEST VALUE117 expect(parseObject.children[7]['doc']).toBe(TEST_YAML);118 expect(parseObject.children[7]['kind']).toBeNull();119 expect(parseObject.children[7]['result']).toBeNull()120 expect(parseObject.children[7]['children']).toBeDefined();121 expect(parseObject.children[7]['children'] instanceof Array).toBe(true);122 expect(parseObject.children[7]['children'].length).toBe(0);123 expect(parseObject.children[7]['parent']).toBe(parseObject)124 });125 });126 describe("JSON Object", function () {127 it('should parse YAML scalars', function () {128 expect(parseObject.result['scalar_key']).not.toBeNull();129 expect(parseObject.result['scalar_key']).toBe('scalar_value');130 });131 it('should parse YAML mappings', function () {132 expect(parseObject.result['mapping_key']).not.toBeNull();133 for (var ref in parseObject.result['mapping_key']) {134 expect(parseObject.result['mapping_key'][ref]).toBe('mapping_val' + ref);135 }136 });137 it('should parse YAML sequences', function () {138 expect(parseObject.result['sequence_key']).not.toBeNull();139 expect(parseObject.result['sequence_key'] instanceof Array).toBe(true);140 for (var ref in parseObject.result['sequence_key']) {141 expect(parseObject.result['sequence_key'][ref]).toBe('sequence_val' + (parseInt(ref) + 1));142 }143 });144 it('should parse YAML nulls', function () {145 expect(parseObject.result['null_key']).toBeDefined();146 expect(parseObject.result['null_key']).toBeNull();147 });148 it('should not contain any extra fields', function () {149 for (var ref in parseObject.result) {150 expect(ref).toMatch(/scalar_key|mapping_key|sequence_key|null_key/)151 }152 });153 });154 });...
hero.service.ts
Source:hero.service.ts
1import { Injectable } from '@angular/core';2// Interface3import { Hero } from './model/hero';4import { HeroDto } from './model/Dto/hero.dto';5// Parse6import * as Parse from 'parse';7// config8import { CONFIG } from '../../../CONFIG';9@Injectable({10 providedIn: 'root',11})12export class HeroService {13 constructor() {}14 /** heroC - parseClass */15 private heroC = Parse.Object.extend(CONFIG.Parse.heroC);16 /**17 * getHeroes - åå¾è±éå表18 *19 * @returns Promise<Hero[]>20 */21 async getHeroes(): Promise<Hero[]> {22 const query = new Parse.Query(this.heroC);23 let result: Hero[] = [];24 try {25 const parseObject = await query.ascending('createdAt').find();26 if (!parseObject) {27 alert('getHeroes failed,Heroes not exist');28 return result;29 }30 result = parseObject.map((item) => new Hero(item));31 } catch (error) {32 console.error(error);33 }34 return result;35 }36 /**37 * getHeroByID - ééIDåå¾è±é38 *39 * @param id - number40 * @returns Promise<Hero>41 */42 async getHeroByID(id: string): Promise<Hero> {43 const query = new Parse.Query(this.heroC);44 let result: Hero = new Hero(new Parse.Object());45 try {46 const parseObject = await query.get(id);47 if (!parseObject) {48 alert('getHeroByID failed, Hero not exist');49 return result;50 }51 result = new Hero(parseObject);52 } catch (error) {53 console.error(error);54 }55 return result;56 }57 /**58 * updateHero - æ´æ°è±é59 *60 * @param hero - HeroDetail61 */62 async updateHero(hero: HeroDto) {63 const query = new Parse.Query(this.heroC);64 try {65 /** getOld */66 let parseObject = await query.get(hero.ID);67 if (!parseObject) {68 alert('hero not exist');69 return;70 }71 /** update */72 parseObject.set('name', hero.name);73 await parseObject.save();74 } catch (error) {75 console.error(error);76 }77 return;78 }79 /**80 * addHero - æ°å¢è±é81 *82 * @param hero - HeroDetail83 */84 async addHero(hero: HeroDto) {85 let newHero = new this.heroC();86 try {87 newHero.set('name', hero.name);88 await newHero.save();89 } catch (error) {90 console.error(error);91 }92 }93 /**94 * deleteHero - åªé¤è±é95 *96 * @param id - number97 */98 async deleteHero(id: string) {99 const query = new Parse.Query(this.heroC);100 try {101 /** getOld */102 const parseObject = await query.get(id);103 if (!parseObject) {104 alert('hero not exist');105 return;106 }107 /** destroy */108 await parseObject.destroy();109 } catch (error) {110 console.error(error);111 }112 return;113 }114 /**115 * searchHeroes - æå°è±é116 *117 * @param term - string118 * @returns Promise<Hero[]>119 */120 async searchHeroes(term: string): Promise<HeroDto[]> {121 if (!term.trim()) {122 return [];123 }124 const query = new Parse.Query(this.heroC);125 let result: HeroDto[] = [];126 try {127 const parseObject = await query128 .matches('name', new RegExp(term))129 .ascending('createdAt')130 .find();131 result = parseObject.map((item) => ({132 ID: item.id,133 name: item.get('name'),134 }));135 } catch (error) {136 console.error(error);137 }138 return result;139 }...
Using AI Code Generation
1import React from 'react';2import { View, Text, StyleSheet, Button } from 'react-native';3import { parseObject } from 'storybook-root';4const styles = StyleSheet.create({5 container: {6 },7});8export default function App() {9 const [data, setData] = React.useState(null);10 React.useEffect(() => {11 parseObject('Storybook', 'Test', '5f4f9c1e3b5e5c5f5e5e5e5e').then((res) => {12 setData(res);13 });14 }, []);15 return (16 <View style={styles.container}>17 <Button title="Click me" onPress={() => console.log(data)} />18 );19}20import { configure } from '@storybook/react-native';21import { getStorybookUI, configureActions } from '@storybook/react-native';22import { parseObject } from 'storybook-root';23const StorybookUIRoot = getStorybookUI({ port: 7007, onDeviceUI: true });24configureActions({25});26parseObject('Storybook', 'Test', '5f4f9c1e3b5e5c5f5e5e5e5e');27export default StorybookUIRoot;28import { AppRegistry, LogBox } from 'react-native';29import App from './test';30import { name as appName } from './app.json';31import StorybookUIRoot from './storybook-root';32LogBox.ignoreLogs(['Setting a timer']);33AppRegistry.registerComponent(appName, () => StorybookUIRoot);34module.exports = {35 webpackFinal: async (config)
Using AI Code Generation
1import { parseObject } from "storybook-root";2import { storiesOf } from "@storybook/react";3import { action } from "@storybook/addon-actions";4storiesOf("Button", module).add("with text", () => (5 <button onClick={action("clicked")}>Hello Button</button>6));7import { parseObject } from "storybook-root";8import { storiesOf } from "@storybook/react";9import { action } from "@storybook/addon-actions";10storiesOf("Button", module).add("with text", () => (11 <button onClick={action("clicked")}>Hello Button</button>12));13import { parseObject } from "storybook-root";14import { storiesOf } from "@storybook/react";15import { action } from "@storybook/addon-actions";16storiesOf("Button", module).add("with text", () => (17 <button onClick={action("clicked")}>Hello Button</button>18));19import { parseObject } from "storybook-root";20import { storiesOf } from "@storybook/react";21import { action } from "@storybook/addon-actions";22storiesOf("Button", module).add("with text", () => (23 <button onClick={action("clicked")}>Hello Button</button>24));25import { parseObject } from "storybook-root";26import { storiesOf } from "@storybook/react";27import { action } from "@storybook/addon-actions";28storiesOf("Button", module).add("with text", () => (29 <button onClick={action("clicked")}>Hello Button</button>30));31import { parseObject } from "storybook-root";32import { storiesOf } from "@storybook/react";33import { action } from "@storybook/addon-actions";34storiesOf("Button", module).add("with text", () => (35 <button onClick={action("clicked")}>Hello Button</button>36));37import { parseObject } from "storybook-root";38import { stories
Using AI Code Generation
1import { parseObject } from "storybook-root";2const object = {3};4const parsedObject = parseObject(object);5console.log(parsedObject);6import { parseArray } from "storybook-root";7const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];8const parsedArray = parseArray(array);9console.log(parsedArray);10import { parseString } from "storybook-root";11const string = "Hello World";12const parsedString = parseString(string);13console.log(parsedString);14import { parseNumber } from "storybook-root";15const number = 1234567890;16const parsedNumber = parseNumber(number);17console.log(parsedNumber);18import { parseBoolean } from "storybook-root";19const boolean = true;20const parsedBoolean = parseBoolean(boolean);21console.log(parsedBoolean);22import { parseNull } from "storybook-root";23const nullValue = null;24const parsedNull = parseNull(nullValue);25console.log(parsedNull);26import { parseUndefined } from "storybook-root";27const undefinedValue = undefined;28const parsedUndefined = parseUndefined(undefinedValue);29console.log(parsedUndefined);30import { parseNaN } from "storybook-root";31const nan = NaN;32const parsedNaN = parseNaN(nan);
Using AI Code Generation
1import { parseObject } from 'storybook-root';2const obj = {3 c: {4 },5};6const parsedObj = parseObject(obj);7console.log(parsedObj);8import { parseObject } from 'storybook-root';9const obj = {10 c: {11 },12};13const parsedObj = parseObject(obj);14console.log(parsedObj);15import { parseObject } from 'storybook-root';16const obj = {17 c: {18 },19};20const parsedObj = parseObject(obj);21console.log(parsedObj);22import { parseObject } from 'storybook-root';23const obj = {24 c: {25 },26};27const parsedObj = parseObject(obj);28console.log(parsedObj);29import { parseObject } from 'storybook-root';30const obj = {31 c: {
Using AI Code Generation
1import { parseObject } from 'storybook-root';2const obj = {3 address: {4 },5};6const parsedObj = parseObject(obj);7console.log(parsedObj);8import { parseObject } from 'storybook-root';9const obj = {10 address: {11 },12};13const parsedObj = parseObject(obj);14console.log(parsedObj);15import { parseObject } from 'storybook-root';16const obj = {17 address: {18 },19};20const parsedObj = parseObject(obj);21console.log(parsedObj);22import { parseObject } from 'storybook-root';23const obj = {24 address: {25 },26};27const parsedObj = parseObject(obj);28console.log(parsedObj);29import { parseObject } from 'storybook-root';30const obj = {31 address: {
Using AI Code Generation
1import { parseObject } from 'storybook-root';2const obj = {3 address: {4 },5};6const parsedObj = parseObject(obj);7console.log(parsedObj);8{9}10import { parseArray } from 'storybook-root';11 {12 address: {13 },14 },15 {16 address: {17 },18 },19];20const parsedArray = parseArray(array);21console.log(parsedArray);22[{23},24{25}]
Using AI Code Generation
1var storybook = require('storybook-root');2var parsed = storybook.parseObject(myObject);3console.log(parsed);4var storybook = require('storybook-root');5var parsed = storybook.parseObject(myObject);6console.log(parsed);7var storybook = require('storybook-root');8var parsed = storybook.parseObject(myObject);9console.log(parsed);10var storybook = require('storybook-root');11var parsed = storybook.parseObject(myObject);12console.log(parsed);13var storybook = require('storybook-root');14var parsed = storybook.parseObject(myObject);15console.log(parsed);16var storybook = require('storybook-root');17var parsed = storybook.parseObject(myObject);18console.log(parsed);19var storybook = require('storybook-root');20var parsed = storybook.parseObject(myObject);21console.log(parsed);22var storybook = require('storybook-root');23var parsed = storybook.parseObject(myObject);24console.log(parsed);25var storybook = require('storybook-root');26var parsed = storybook.parseObject(myObject);27console.log(parsed);28var storybook = require('storybook-root');29var parsed = storybook.parseObject(myObject);30console.log(parsed);31var storybook = require('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!!