Best JavaScript code snippet using storybook-root
js2form.js
Source:js2form.js
1/โ**2 * Copyright (c) 2010 Maxim Vasiliev3 *4 * Permission is hereby granted, free of charge, to any person obtaining a copy5 * of this software and associated documentation files (the "Software"), to deal6 * in the Software without restriction, including without limitation the rights7 * to use, copy, modify, merge, publish, distribute, sublicense, and/โor sell8 * copies of the Software, and to permit persons to whom the Software is9 * furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN20 * THE SOFTWARE.21 *22 * @author Maxim Vasiliev23 * Date: 19.09.1124 * Time: 23:4025 */โ26var js2form = (function()27{28 "use strict";29 var _subArrayRegexp = /โ^\[\d+?\]/โ,30 _subObjectRegexp = /โ^[a-zA-Z_][a-zA-Z_0-9]+/โ,31 _arrayItemRegexp = /โ\[[0-9]+?\]$/โ,32 _lastIndexedArrayRegexp = /โ(.*)(\[)([0-9]*)(\])$/โ,33 _arrayOfArraysRegexp = /โ\[([0-9]+)\]\[([0-9]+)\]/โg,34 _inputOrTextareaRegexp = /โINPUT|TEXTAREA/โi;35 /โ**36 *37 * @param rootNode38 * @param data39 * @param delimiter40 * @param nodeCallback41 * @param useIdIfEmptyName42 */โ43 function js2form(rootNode, data, delimiter, nodeCallback, useIdIfEmptyName)44 {45 if (arguments.length < 3) delimiter = '.';46 if (arguments.length < 4) nodeCallback = null;47 if (arguments.length < 5) useIdIfEmptyName = false;48 var fieldValues,49 formFieldsByName;50 fieldValues = object2array(data);51 formFieldsByName = getFields(rootNode, useIdIfEmptyName, delimiter, {}, true);52 for (var i = 0; i < fieldValues.length; i++)53 {54 var fieldName = fieldValues[i].name,55 fieldValue = fieldValues[i].value;56 if (typeof formFieldsByName[fieldName] != 'undefined')57 {58 setValue(formFieldsByName[fieldName], fieldValue);59 }60 else if (typeof formFieldsByName[fieldName.replace(_arrayItemRegexp, '[]')] != 'undefined')61 {62 setValue(formFieldsByName[fieldName.replace(_arrayItemRegexp, '[]')], fieldValue);63 }64 }65 }66 function setValue(field, value)67 {68 var children, i, l;69 if (field instanceof Array)70 {71 for(i = 0; i < field.length; i++)72 {73 if (field[i].value == value) field[i].checked = true;74 }75 }76 else if (_inputOrTextareaRegexp.test(field.nodeName))77 {78 field.value = value;79 }80 else if (/โSELECT/โi.test(field.nodeName))81 {82 children = field.getElementsByTagName('option');83 for (i = 0,l = children.length; i < l; i++)84 {85 if (children[i].value == value)86 {87 children[i].selected = true;88 if (field.multiple) break;89 }90 else if (!field.multiple)91 {92 children[i].selected = false;93 }94 }95 }96 }97 function getFields(rootNode, useIdIfEmptyName, delimiter, arrayIndexes, shouldClean)98 {99 if (arguments.length < 4) arrayIndexes = {};100 var result = {},101 currNode = rootNode.firstChild,102 name, nameNormalized,103 subFieldName,104 i, j, l,105 options;106 while (currNode)107 {108 name = '';109 if (currNode.name && currNode.name != '')110 {111 name = currNode.name;112 }113 else if (useIdIfEmptyName && currNode.id && currNode.id != '')114 {115 name = currNode.id;116 }117 if (name == '')118 {119 var subFields = getFields(currNode, useIdIfEmptyName, delimiter, arrayIndexes, shouldClean);120 for (subFieldName in subFields)121 {122 if (typeof result[subFieldName] == 'undefined')123 {124 result[subFieldName] = subFields[subFieldName];125 }126 else127 {128 for (i = 0; i < subFields[subFieldName].length; i++)129 {130 result[subFieldName].push(subFields[subFieldName][i]);131 }132 }133 }134 }135 else136 {137 if (/โSELECT/โi.test(currNode.nodeName))138 {139 for(j = 0, options = currNode.getElementsByTagName('option'), l = options.length; j < l; j++)140 {141 if (shouldClean)142 {143 options[j].selected = false;144 }145 nameNormalized = normalizeName(name, delimiter, arrayIndexes);146 result[nameNormalized] = currNode;147 }148 }149 else if (/โINPUT/โi.test(currNode.nodeName) && /โCHECKBOX|RADIO/โi.test(currNode.type))150 {151 if(shouldClean)152 {153 currNode.checked = false;154 }155 nameNormalized = normalizeName(name, delimiter, arrayIndexes);156 nameNormalized = nameNormalized.replace(_arrayItemRegexp, '[]');157 if (!result[nameNormalized]) result[nameNormalized] = [];158 result[nameNormalized].push(currNode);159 }160 else161 {162 if (shouldClean)163 {164 currNode.value = '';165 }166 nameNormalized = normalizeName(name, delimiter, arrayIndexes);167 result[nameNormalized] = currNode;168 }169 }170 currNode = currNode.nextSibling;171 }172 return result;173 }174 /โ**175 * Normalizes names of arrays, puts correct indexes (consecutive and ordered by element appearance in HTML)176 * @param name177 * @param delimiter178 * @param arrayIndexes179 */โ180 function normalizeName(name, delimiter, arrayIndexes)181 {182 var nameChunksNormalized = [],183 nameChunks = name.split(delimiter),184 currChunk,185 nameMatches,186 nameNormalized,187 currIndex,188 newIndex,189 i;190 name = name.replace(_arrayOfArraysRegexp, '[$1].[$2]');191 for (i = 0; i < nameChunks.length; i++)192 {193 currChunk = nameChunks[i];194 nameChunksNormalized.push(currChunk);195 nameMatches = currChunk.match(_lastIndexedArrayRegexp);196 if (nameMatches != null)197 {198 nameNormalized = nameChunksNormalized.join(delimiter);199 currIndex = nameNormalized.replace(_lastIndexedArrayRegexp, '$3');200 nameNormalized = nameNormalized.replace(_lastIndexedArrayRegexp, '$1');201 if (typeof (arrayIndexes[nameNormalized]) == 'undefined')202 {203 arrayIndexes[nameNormalized] = {204 lastIndex: -1,205 indexes: {}206 };207 }208 if (currIndex == '' || typeof arrayIndexes[nameNormalized].indexes[currIndex] == 'undefined')209 {210 arrayIndexes[nameNormalized].lastIndex++;211 arrayIndexes[nameNormalized].indexes[currIndex] = arrayIndexes[nameNormalized].lastIndex;212 }213 newIndex = arrayIndexes[nameNormalized].indexes[currIndex];214 nameChunksNormalized[nameChunksNormalized.length - 1] = currChunk.replace(_lastIndexedArrayRegexp, '$1$2' + newIndex + '$4');215 }216 }217 nameNormalized = nameChunksNormalized.join(delimiter);218 nameNormalized = nameNormalized.replace('].[', '][');219 return nameNormalized;220 }221 function object2array(obj, lvl)222 {223 var result = [], i, name;224 if (arguments.length == 1) lvl = 0;225 if (obj == null)226 {227 result = [{ name: "", value: null }];228 }229 else if (typeof obj == 'string' || typeof obj == 'number' || typeof obj == 'date' || typeof obj == 'boolean')230 {231 result = [232 { name: "", value : obj }233 ];234 }235 else if (obj instanceof Array)236 {237 for (i = 0; i < obj.length; i++)238 {239 name = "[" + i + "]";240 result = result.concat(getSubValues(obj[i], name, lvl + 1));241 }242 }243 else244 {245 for (i in obj)246 {247 name = i;248 result = result.concat(getSubValues(obj[i], name, lvl + 1));249 }250 }251 return result;252 }253 function getSubValues(subObj, name, lvl)254 {255 var itemName;256 var result = [], tempResult = object2array(subObj, lvl + 1), i, tempItem;257 for (i = 0; i < tempResult.length; i++)258 {259 itemName = name;260 if (_subArrayRegexp.test(tempResult[i].name))261 {262 itemName += tempResult[i].name;263 }264 else if (_subObjectRegexp.test(tempResult[i].name))265 {266 itemName += '.' + tempResult[i].name;267 }268 tempItem = { name: itemName, value: tempResult[i].value };269 result.push(tempItem);270 }271 return result;272 }273 return js2form;...
_Executor.js
Source:_Executor.js
1/โ/โ>>built2define("dojox/โcalc/โ_Executor",["dojo/โ_base/โkernel","dojo/โ_base/โdeclare","dojo/โ_base/โlang","dojo/โnumber","dijit/โ_base/โmanager","dijit/โ_WidgetBase","dijit/โ_TemplatedMixin","dojox/โmath/โ_base"],function(_1,_2,_3,_4,_5,_6,_7,_8){3_1.experimental("dojox.calc");4var _9,_a;5var _b=(1<<30)-35;6var _c=_2("dojox.calc._Executor",[_6,_7],{templateString:"<iframe src=\""+require.toUrl("dojox/โcalc/โ_ExecutorIframe.html")+"\" style=\"display:none;\" onload=\"if(arguments[0] && arguments[0].Function)"+_5._scopeName+".byNode(this)._onLoad(arguments[0])\"></โiframe>",_onLoad:function(_d){7_9=_d;8_d.outerPrompt=window.prompt;9_d.dojox={math:{}};10for(var f in _8){11_d.dojox.math[f]=_3.hitch(_8,f);12}13if("toFrac" in _a){14_d.toFracCall=_3.hitch(_a,"toFrac");15this.Function("toFrac","x","return toFracCall(x)");16}17_d.isJavaScriptLanguage=_4.format(1.5,{pattern:"#.#"})=="1.5";18_d.Ans=0;19_d.pi=Math.PI;20_d.eps=Math.E;21_d.powCall=_3.hitch(_a,"pow");22this.normalizedFunction("sqrt","x","return Math.sqrt(x)");23this.normalizedFunction("sin","x","return Math.sin(x)");24this.normalizedFunction("cos","x","return Math.cos(x)");25this.normalizedFunction("tan","x","return Math.tan(x)");26this.normalizedFunction("asin","x","return Math.asin(x)");27this.normalizedFunction("acos","x","return Math.acos(x)");28this.normalizedFunction("atan","x","return Math.atan(x)");29this.normalizedFunction("atan2","y, x","return Math.atan2(y, x)");30this.normalizedFunction("Round","x","return Math.round(x)");31this.normalizedFunction("Int","x","return Math.floor(x)");32this.normalizedFunction("Ceil","x","return Math.ceil(x)");33this.normalizedFunction("ln","x","return Math.log(x)");34this.normalizedFunction("log","x","return Math.log(x)/โMath.log(10)");35this.normalizedFunction("pow","x, y","return powCall(x,y)");36this.normalizedFunction("permutations","n, r","return dojox.math.permutations(n, r);");37this.normalizedFunction("P","n, r","return dojox.math.permutations(n, r);");38this.normalizedFunction("combinations","n, r","return dojox.math.combinations(n, r);");39this.normalizedFunction("C","n, r","return dojox.math.combinations(n, r)");40this.normalizedFunction("toRadix","number, baseOut","if(!baseOut){ baseOut = 10; } if(typeof number == 'string'){ number = parseFloat(number); }return number.toString(baseOut);");41this.normalizedFunction("toBin","number","return toRadix(number, 2)");42this.normalizedFunction("toOct","number","return toRadix(number, 8)");43this.normalizedFunction("toHex","number","return toRadix(number, 16)");44this.onLoad();45},onLoad:function(){46},Function:function(_e,_f,_10){47return _3.hitch(_9,_9.Function.apply(_9,arguments));48},normalizedFunction:function(_11,_12,_13){49return _3.hitch(_9,_9.normalizedFunction.apply(_9,arguments));50},deleteFunction:function(_14){51_9[_14]=undefined;52delete _9[_14];53},eval:function(_15){54return _9.eval.apply(_9,arguments);55},destroy:function(){56this.inherited(arguments);57_9=null;58}});59return _a={pow:function(_16,_17){60function _18(n){61return Math.floor(n)==n;62};63if(_16>=0||_18(_17)){64return Math.pow(_16,_17);65}else{66var inv=1/โ_17;67return (_18(inv)&&(inv&1))?-Math.pow(-_16,_17):NaN;68}69},approx:function(r){70if(typeof r=="number"){71return Math.round(r*_b)/โ_b;72}73return r;74},_Executor:_c};...
normalizeProp.ts
Source:normalizeProp.ts
1import { isArray, isString, isObject, hyphenate } from './โ'2import { isNoUnitNumericStyleProp } from './โdomAttrConfig'3export type NormalizedStyle = Record<string, string | number>4export function normalizeStyle(value: unknown): NormalizedStyle | undefined {5 if (isArray(value)) {6 const res: NormalizedStyle = {}7 for (let i = 0; i < value.length; i++) {8 const item = value[i]9 const normalized = normalizeStyle(10 isString(item) ? parseStringStyle(item) : item11 )12 if (normalized) {13 for (const key in normalized) {14 res[key] = normalized[key]15 }16 }17 }18 return res19 } else if (isObject(value)) {20 return value21 }22}23const listDelimiterRE = /โ;(?![^(]*\))/โg24const propertyDelimiterRE = /โ:(.+)/โ25export function parseStringStyle(cssText: string): NormalizedStyle {26 const ret: NormalizedStyle = {}27 cssText.split(listDelimiterRE).forEach(item => {28 if (item) {29 const tmp = item.split(propertyDelimiterRE)30 tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())31 }32 })33 return ret34}35export function stringifyStyle(styles: NormalizedStyle | undefined): string {36 let ret = ''37 if (!styles) {38 return ret39 }40 for (const key in styles) {41 const value = styles[key]42 const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key)43 if (44 isString(value) ||45 (typeof value === 'number' && isNoUnitNumericStyleProp(normalizedKey))46 ) {47 /โ/โ only render valid values48 ret += `${normalizedKey}:${value};`49 }50 }51 return ret52}53export function normalizeClass(value: unknown): string {54 let res = ''55 if (isString(value)) {56 res = value57 } else if (isArray(value)) {58 for (let i = 0; i < value.length; i++) {59 const normalized = normalizeClass(value[i])60 if (normalized) {61 res += normalized + ' '62 }63 }64 } else if (isObject(value)) {65 for (const name in value) {66 if (value[name]) {67 res += name + ' '68 }69 }70 }71 return res.trim()...
Using AI Code Generation
1import { storiesOf } from '@storybook/โreact';2import { linkTo } from '@storybook/โaddon-links';3storiesOf('Button', module)4 .add('with text', () => (5 <Button onClick={linkTo('Button', 'with some emoji')}>Hello Button</โButton>6 .add('with some emoji', () => (7 <Button onClick={linkTo('Welcome')}>๐ ๐ ๐ ๐ฏ</โButton>8 ));9module.exports = {10 module: {11 {12 test: /โ\.(js|jsx)$/โ,13 {14 options: {15 {16 },17 },18 },19 },20 },21};22module.exports = {23 module: {24 {25 test: /โ\.(ts|tsx)$/โ,26 {27 options: {28 {29 },30 },31 },32 {33 loader: require.resolve('react-docgen-typescript-loader'),34 },35 },36 },37 resolve: {38 },39};40module.exports = {41 module: {42 {43 test: /โ\.(vue)$/โ,44 },45 },46 resolve: {47 alias: {
Using AI Code Generation
1import { storiesOf } from '@storybook/โreact';2import { withInfo } from '@storybook/โaddon-info';3import { withKnobs, text, boolean, number } from '@storybook/โaddon-knobs';4import { withNotes } from '@storybook/โaddon-notes';5import { withViewport } from '@storybook/โaddon-viewport';6import { withBackgrounds } from '@storybook/โaddon-backgrounds';7import { withOptions } from '@storybook/โaddon-options';8import { withLinks } from '@storybook/โaddon-links';9import { withConsole } from '@storybook/โaddon-console';10import { withTests } from '@storybook/โaddon-jest';11import { withA11y } from '@storybook/โaddon-a11y';12import { withPropsTable } from 'storybook-addon-react-docgen';13import { withReadme } from 'storybook-readme';14import { withDocs } from 'storybook-readme';15import { withReadme } from 'storybook-readme';16import { storiesOf } from '../โ../โ../โ.storybook/โfacade';17import { withInfo } from '../โ../โ../โ.storybook/โaddons/โinfo';18import { withKnobs, text, boolean, number } from '../โ../โ../โ.storybook/โaddons/โknobs';19import { withNotes } from '../โ../โ../โ.storybook/โaddons/โnotes';20import { withViewport } from '../โ../โ../โ.storybook/โaddons/โviewport';21import { withBackgrounds } from '../โ../โ../โ.storybook/โaddons/โbackgrounds';22import { withOptions } from '../โ../โ../โ.storybook/โaddons/โoptions';23import { withLinks } from '../โ../โ../โ.storybook/โaddons/โlinks';24import { withConsole } from '../โ../โ../โ.storybook/โaddons/โconsole';25import { withTests } from '../โ../โ../โ.storybook/โaddons/โjest';26import { withA11y } from '../โ../โ../โ.storybook/โaddons/โa11y';27import { withPropsTable } from '../โ../โ../โ.storybook/โaddons/โreact-docgen';28import { withReadme } from '../โ../โ../โ.storybook/โaddons/โreadme';29import { withDocs } from '../โ../โ../โ.storybook/โaddons/โdocs';30import { withReadme } from '../โ../โ../โ.storybook/โaddons/โdocs';31| [Console](
Using AI Code Generation
1import { storiesOf } from 'storybook-root'2storiesOf('Button', module)3 .add('with text', () => <button>Click Me</โbutton>)4 .add('with some emoji', () => (5 ));6"scripts": {7}8{9 "storybook": {10 "webpackConfig": {11 "module": {12 {13 }14 }15 }16 }17}
Using AI Code Generation
1const path = require('path');2const rootPath = path.resolve(__dirname, '../โ');3const storybookRoot = require('storybook-root')(rootPath);4module.exports = {5 stories: [storybookRoot('stories/โ**/โ*.stories.js')],6};7const path = require('path');8const rootPath = path.resolve(__dirname, '../โ');9const storybookRoot = require('storybook-root')(rootPath);10module.exports = async ({ config }) => {11 config.module.rules.push({12 loaders: [require.resolve('@storybook/โaddon-storysource/โloader')],13 include: [storybookRoot('stories')],14 });15 return config;16};17MIT ยฉ [Dhruv Jain](
Using AI Code Generation
1import { root } from 'storybook-root';2import { storiesOf } from '@storybook/โreact';3import { withKnobs, text } from '@storybook/โaddon-knobs';4const stories = storiesOf('Test', module);5stories.addDecorator(withKnobs);6stories.add('Test', () => {7 const textValue = text('Text', 'Hello World');8 return (9 <h1>{textValue}</โh1>10 );11});12This package is a wrapper around [babel-plugin-module-resolver](
Using AI Code Generation
1import { withRootDecorator } from 'storybook-root-decorator';2import { addDecorator } from '@storybook/โreact';3addDecorator(withRootDecorator);4import { withRootDecorator } from 'storybook-root-decorator';5import { addDecorator } from '@storybook/โreact';6addDecorator(withRootDecorator);7import { withRootDecorator } from 'storybook-root-decorator';8import { addDecorator } from '@storybook/โreact';9addDecorator(withRootDecorator);10 - `options` (optional): `Object`11## withRootDecorator(options)12 - `options` (optional): `Object`13## withRootDecorator(options)14 - `options` (optional): `Object`
Using AI Code Generation
1import { storiesOf } from 'storybook-root';2storiesOf('Button', module).add('with text', () => <Button>Hello Button</โButton>);3module.exports = (baseConfig, env, config) => {4 return config;5};6{7 "scripts": {8 },9 "devDependencies": {10 }11}12{13}14{15 "scripts": {16 },17 "devDependencies": {18 }19}
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!!