How to use parseIncludeExclude method in storybook-root

Best JavaScript code snippet using storybook-root

parse.ts

Source:parse.ts Github

copy

Full Screen

...96 const match1 = matches[1];97 const [_, ...fnArgs] = matches;98 const afterMatch1 = str.slice(str.indexOf(match1) + match1.length);99 let result = fn(...fnArgs);100 result = parseIncludeExclude("include", afterMatch1, result);101 result = parseIncludeExclude("exclude", afterMatch1, result);102 return result;103}104export const groupToCombination = (str: string, data: Record<string, number[][][]>): number[][] => {105 // simple ones without include/exclude106 if (regSingle.test(str)) {107 return [splitToNumbers(str)];108 }109 if (regCombinationLiteral.test(str)) {110 return splitToNumbers(str).map(wrapWithArray);111 }112 if (regFormationLiteral.test(str)) {113 return uniq(trim(str, "[]").split(",")).map((str) => splitToNumbers(str));114 }115 if (regREF.test(str)) {116 if (!data) return [];117 const iFirstParenthesisClosing = findClosingParenthesis(str, str.indexOf("("));118 const mainFunctionArguments = str.slice(0, iFirstParenthesisClosing + 1);119 const matches = regREF.exec(mainFunctionArguments);120 if (!matches) return [];121 const rawArguments = matches[1].split(",").filter((str) => str.length > 0);122 const addition = trim(str.slice(iFirstParenthesisClosing + 1));123 if (rawArguments.length === 0) return [];124 let result: number[][] = [];125 const args = rawArguments.map((arg) => {126 const [name, index] = arg.split(".");127 return { name, index: Number(index) };128 });129 if (uniq(args.map((g) => g.name)).length === 1) {130 // algorithm for referencing from one single line: just merge references into one group131 const referredLine = data[args[0].name];132 if (referredLine) {133 const indicesToKeep = args.map((g) => g.index);134 referredLine.forEach((c) => {135 result.push(indicesToKeep.flatMap((j) => c[j]));136 });137 }138 } else {139 // algorithm for referencing from more lines: create a group of cartesian combinations140 result = cartesian(...args.map(({ name, index }) => data[name].map((l) => l[index])).map(uniq)).map((g) => g.flat());141 }142 result = uniqBy(result, (arr) => arr.map(identity).sort().join(""));143 result = parseIncludeExclude("include", addition, result);144 result = parseIncludeExclude("exclude", addition, result);145 return result;146 }147 if (regKCombination.test(str)) {148 const matches = regKCombination.exec(str);149 if (!matches) return [];150 const ksize = Number(matches[1]);151 const iFirstComma = str.indexOf(",");152 const iFirstParenthesisClosing = findClosingParenthesis(str, str.indexOf("("));153 const content = trim(str.slice(iFirstComma + 1, iFirstParenthesisClosing));154 const addition = trim(str.slice(iFirstParenthesisClosing + 1));155 // oh no156 const combinations = groupToCombination(content, data);157 if (!combinations) return [];158 let result = combinations.flatMap((set) => kcombination(ksize, set));159 result = uniqBy(result, (arr) => arr.map(identity).sort().join(""));160 result = parseIncludeExclude("include", addition, result);161 result = parseIncludeExclude("exclude", addition, result);162 result = parseIncludeExclude("outside-include", addition, result);163 result = parseIncludeExclude("outside-exclude", addition, result);164 return result;165 }166 const resultAnyLiteral = tryParseForResult(regAnyLiteral, str, (m) => {167 const formations = formation(...m.split("").map(() => digits.map(wrapWithArray)));168 return uniqBy(formations, (arr) => arr.flat().sort().join("")).map((item) => item.map((v) => v[0]));169 });170 if (resultAnyLiteral !== false) return resultAnyLiteral;171 const resultSum = tryParseForResult(regSum, str, (sumInput: string, size: string): number[][] => {172 const sums: number[] = [];173 if (sumInput.indexOf("~") > -1) {174 const [min, max] = sumInput.split("~").map(trim).map(Number);175 range(min, max + 1, 1).forEach((value) => sums.push(value));176 } else if (sumInput.indexOf(",") > -1) {177 sumInput...

Full Screen

Full Screen

userstyles

Source:userstyles Github

copy

Full Screen

...87{88 if(enabled)89 handle(wv.mainFrame, styles);90}//}}}91function parseIncludeExclude(array) //{{{92{93 var i, rule;94 for (i=0; i<array.length; i++) 95 {96 rule = array[i];97 if (regexes.isRegExp.test(rule)) 98 {99 array[i] = { 100 regExp : new RegExp(rule.substring(1, rule.length-1)), 101 isTld : regexes.isTld.test(rule) 102 };103 }104 else 105 {106 array[i] = { 107 regExp : new RegExp(rule.replace(/\*/g, ".*")), 108 isTld : regexes.isTld.test(rule) 109 };110 }111 }112}//}}}113function uriSplit(uri) 114{115 var parts, scheme, host, path, idx; 116 parts = uri.split("://");117 if (parts[0] === uri) 118 return null;119 scheme = parts[0];120 idx = parts[1].indexOf("/");121 if (idx == -1) 122 {123 host = parts[1];124 path = null;125 }126 else 127 {128 host = parts[1].substring(0, idx);129 path = parts[1].substring(idx);130 }131 return { path : path, host: host, scheme : scheme }; 132}133function parseStyle(path) //{{{134{135 var userstyle;136 var i, items, key, value, idx, m, numVal;137 var curStyle = io.read(path);138 if (!curStyle || (/^\s*$/).test(curStyle)) 139 return;140 var metaStart = curStyle.search(/(^|\n)\/\/\s*==UserStyle==/);141 var metaEnd = curStyle.search(/\n\/\/\s*==\/UserStyle==/);142 userstyle = new UserStyle();143 if (metaStart == -1 || metaEnd == -1) 144 {145 userstyle.style = curStyle;146 userstyle.offset = 1;147 userstyle.include = [ { regExp : /.*/, isTld : false} ];148 styles.push(userstyle);149 return;150 }151 var meta = curStyle.substring(metaStart, metaEnd).split("\n");152 var styleStart = curStyle.substring(metaEnd+1).indexOf("\n") + metaEnd + 1;153 var regValue = /\s[^\/@]\S?/;154 var regIsRule = /^\s*\/\/\s*@/;155 for (i=1; i<meta.length; i++) 156 {157 if (! (regIsRule.test(meta[i])) )158 continue;159 try 160 {161 items = meta[i].split(/\s+/, 2);162 key = items[1].substring(1).trim();163 idx = meta[i].search(regValue);164 value = idx >= 0 ? meta[i].substring(idx+1).trim() : null;165 if (key == "description" || 166 key == "downloadURL" || 167 key == "icon" || 168 key == "name" || 169 key == "updateURL" || 170 key == "version") 171 {172 userstyle[key] = value;173 }174 else if (typeof userstyle[key] == "number") 175 {176 try 177 {178 numVal = parseInt(value, 10);179 if (!isNaN(numVal)) 180 userstyle[key] = numVal;181 }182 catch (e) {183 script.debug(e);184 }185 }186 else if (userstyle[key] instanceof Array) 187 userstyle[key] = userstyle[key].concat(value.match(/\S+/g));188 }189 catch(e)190 {191 script.debug(e);192 }193 }194 if (userstyle.include.length === 0) 195 userstyle.include.push({regExp : /.*/, isTld : false});196 else197 parseIncludeExclude(userstyle.include);198 parseIncludeExclude(userstyle.exclude);199 userstyle.style = curStyle.substring(styleStart);200 userstyle.offset = meta.length + 1;201 styles.push(userstyle);202}//}}}203function parseStyles(styles) //{{{204{205 var i, path;206 for (i=0; i<styles.length; i++) 207 {208 if (system.fileTest(styles[i], FileTest.regular | FileTest.symlink)) 209 parseScript(styles[i]);210 }211 [ "userstyles" ].forEach(function(path) {212 var styleDir = data.configDir + "/" + path;...

Full Screen

Full Screen

csf-to-mdx.js

Source:csf-to-mdx.js Github

copy

Full Screen

...13 return code;14 })15 .join('\n');16}17function parseIncludeExclude(prop) {18 const { code } = recast.prettyPrint(prop, {});19 // eslint-disable-next-line no-eval20 return eval(code);21}22/**23 * Convert a component's module story file into an MDX file24 *25 * For example:26 *27 * ```28 * input { Button } from './Button';29 * export default {30 * title: 'Button'31 * }32 * export const story = () => <Button label="The Button" />;33 * ```34 *35 * Becomes:36 *37 * ```38 * import { Meta, Story } from '@storybook/addon-docs/blocks';39 * input { Button } from './Button';40 *41 * <Meta title='Button' />42 *43 * <Story name='story'>44 * <Button label="The Button" />45 * </Story>46 * ```47 */48export default function transformer(file, api) {49 const j = api.jscodeshift;50 const root = j(file.source);51 // FIXME: save out all the storyFn.story = { ... }52 const storyKeyToStory = {};53 // save out includeStories / excludeStories54 const meta = {};55 function makeAttr(key, val) {56 return j.jsxAttribute(57 j.jsxIdentifier(key),58 val.type === 'Literal' ? val : j.jsxExpressionContainer(val)59 );60 }61 function getStoryContents(node) {62 return node.type === 'ArrowFunctionExpression' && node.body.type === 'JSXElement'63 ? node.body64 : j.jsxExpressionContainer(node);65 }66 function getName(storyKey) {67 const story = storyKeyToStory[storyKey];68 if (story) {69 const name = story.properties.find(prop => prop.key.name === 'name');70 if (name && name.value.type === 'Literal') {71 return name.value.value;72 }73 }74 return storyKey;75 }76 function getStoryAttrs(storyKey) {77 const attrs = [];78 const story = storyKeyToStory[storyKey];79 if (story) {80 story.properties.forEach(prop => {81 const { key, value } = prop;82 if (key.name !== 'name') {83 attrs.push(makeAttr(key.name, value));84 }85 });86 }87 return attrs;88 }89 // 1. If the program does not have `export default { title: '....' }, skip it90 const defaultExportWithTitle = root91 .find(j.ExportDefaultDeclaration)92 .filter(def => def.node.declaration.properties.map(p => p.key.name).includes('title'));93 if (defaultExportWithTitle.size() === 0) {94 return root.toSource();95 }96 // 2a. Add imports from '@storybook/addon-docs/blocks'97 root98 .find(j.ImportDeclaration)99 .at(-1)100 .insertAfter(j.emptyStatement())101 .insertAfter(102 j.importDeclaration(103 [j.importSpecifier(j.identifier('Meta')), j.importSpecifier(j.identifier('Story'))],104 j.literal('@storybook/addon-docs/blocks')105 )106 );107 // 2b. Remove react import which is implicit108 root109 .find(j.ImportDeclaration)110 .filter(decl => decl.node.source.value === 'react')111 .remove();112 // 3. Save out all the excluded stories113 defaultExportWithTitle.forEach(exp => {114 exp.node.declaration.properties.forEach(p => {115 if (['includeStories', 'excludeStories'].includes(p.key.name)) {116 meta[p.key.name] = parseIncludeExclude(p.value);117 }118 });119 });120 // 4. Collect all the story exports in storyKeyToStory[key] = null;121 const namedExports = root.find(j.ExportNamedDeclaration);122 namedExports.forEach(exp => {123 const storyKey = exp.node.declaration.declarations[0].id.name;124 if (isExportStory(storyKey, meta)) {125 storyKeyToStory[storyKey] = null;126 }127 });128 // 5. Collect all the storyKey.story in storyKeyToStory and also remove them129 const storyAssignments = root.find(j.AssignmentExpression).filter(exp => {130 const { left } = exp.node;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseIncludeExclude } from "storybook-root-decorator";2import { addDecorator } from "@storybook/react";3import { withRootDecorator } from "storybook-root-decorator";4const { include, exclude } = parseIncludeExclude({5});6addDecorator(withRootDecorator({ include, exclude }));

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseIncludeExclude } from 'storybook-root-decorator';2const { include, exclude } = parseIncludeExclude({3});4import { withRootDecorator } from 'storybook-root-decorator';5import { addDecorator } from '@storybook/react';6import { withInfo } from '@storybook/addon-info';7const { include, exclude } = parseIncludeExclude({8});9addDecorator(withRootDecorator({ include, exclude }));10addDecorator(withInfo);

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { parseIncludeExclude } = require('storybook-root-alias');3const rootPath = path.resolve(__dirname, '../..');4module.exports = {5 core: {6 },7 stories: ['../stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],8 webpackFinal: async (config) => {9 config.module.rules[0].include = parseIncludeExclude(10 );11 config.module.rules[0].exclude = parseIncludeExclude(12 );13 return config;14 }15};16module.exports = {17 stories: ['../stories/**/*.stories.@(ts|tsx|js|jsx|mdx)'],18 webpackFinal: async (config) => {19 config.module.rules[0].include = parseIncludeExclude(20 );21 config.module.rules[0].exclude = parseIncludeExclude(22 );23 return config;24 }25};26import { addDecorator } from '@storybook/react';27import { withA11y } from '@storybook/addon-a11y';28import { withKnobs

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseIncludeExclude } from 'storybook-root';2const { include, exclude } = parseIncludeExclude({3});4console.log(include, exclude);5import { parseIncludeExclude } from 'storybook-root';6const { include, exclude } = parseIncludeExclude({7});8console.log(include, exclude);9import { parseIncludeExclude } from 'storybook-root';10const { include, exclude } = parseIncludeExclude({11});12console.log(include, exclude);13import { parseIncludeExclude } from 'storybook-root';14const { include, exclude } = parseIncludeExclude({15});16console.log(include, exclude);17import { parseIncludeExclude } from 'storybook-root';18const { include, exclude } = parseIncludeExclude({});19console.log(include, exclude);20import { parseIncludeExclude } from 'storybook-root';21const { include, exclude } = parseIncludeExclude({22});23console.log(include, exclude);24import { parseIncludeExclude } from 'storybook-root';25const { include, exclude } = parseIncludeExclude({

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseIncludeExclude } from 'storybook-root'2const { include, exclude } = parseIncludeExclude({3})4console.log({ include, exclude })5const { include, exclude } = parseIncludeExclude({6 include: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],7 exclude: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],8})9console.log({ include, exclude })10const { include, exclude } = parseIncludeExclude({11 include: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],12 exclude: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],13})14console.log({ include, exclude })15const { include, exclude } = parseIncludeExclude({16 include: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],17 exclude: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],18})19console.log({ include, exclude })20const { include, exclude } = parseIncludeExclude({21 include: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],22 exclude: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],23})24console.log({ include, exclude })25const { include, exclude } = parseIncludeExclude({26 include: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],27 exclude: ['../packages/**/src/**/*.stories.@(js|jsx|ts|tsx)'],28})29console.log({ include, exclude })30const { include

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseIncludeExclude } = require('storybook-root-cause');2const { include, exclude } = parseIncludeExclude({3 include: 'src/**/stories/**/*.(stories|story).(js|jsx|ts|tsx)',4 exclude: 'src/**/stories/**/.*.stories.(js|jsx|ts|tsx)',5});6console.log('include', include);7console.log('exclude', exclude);8 'src/**/stories/**/*.(stories|story).(js|jsx|ts|tsx)',9 'src/**/stories/**/.*.stories.(js|jsx|ts|tsx)'10exclude [ 'src/**/stories/**/.*.stories.(js|jsx|ts|tsx)' ]11{12 "scripts": {13 }14}15const { parseIncludeExclude } = require('storybook-root-cause');16const globby = require('globby');17const { include, exclude } = parseIncludeExclude({18 include: 'src/**/stories/**/*.(stories|story).(js|jsx|ts|tsx)',19 exclude: 'src/**/stories/**/.*.stories.(js|jsx|ts|tsx)',20});21const pattern = [...include, `!${exclude}`];22const paths = globby.sync(pattern);23console.log('paths', paths);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { parseIncludeExclude } = require('storybook-root-require');2const { include, exclude } = parseIncludeExclude('src');3module.exports = {4};5module.exports = {6 moduleNameMapper: {7 '^@/(.*)$': '<rootDir>/src/$1',8 },9 transform: {10 },11};12const { parseIncludeExclude } = require('storybook-root-require');13const { include, exclude } = parseIncludeExclude('src');14module.exports = {15};16module.exports = {17 moduleNameMapper: {18 '^@/(.*)$': '<rootDir>/src/$1',19 },20 transform: {21 },

Full Screen

Using AI Code Generation

copy

Full Screen

1import { parseIncludeExclude } from 'storybook-root';2const { include, exclude } = parseIncludeExclude('my-package');3console.log({ include, exclude });4const { parseIncludeExclude } = require('storybook-root');5const { include, exclude } = parseIncludeExclude('my-package');6console.log({ include, exclude });7const { parseIncludeExclude } = require('storybook-root');8const { include, exclude } = parseIncludeExclude('my-package');9console.log({ include, exclude });10const { parseIncludeExclude } = require('storybook-root');11const { include, exclude } = parseIncludeExclude('my-package');12console.log({ include, exclude });13const { parseIncludeExclude } = require('storybook-root');14const { include, exclude } = parseIncludeExclude('my-package');15console.log({ include, exclude });16const { parseIncludeExclude } = require('storybook-root');17const { include, exclude } = parseIncludeExclude('my-package');18console.log({ include, exclude });19const { parseIncludeExclude } = require('storybook-root');20const { include, exclude } = parseIncludeExclude('my-package');21console.log({ include, exclude });

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful