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!!