Best JavaScript code snippet using storybook-root
DictionaryIdentifierNamesGenerator.ts
Source:DictionaryIdentifierNamesGenerator.ts
1import { inject, injectable } from 'inversify';2import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';3import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';4import { IOptions } from '../../interfaces/options/IOptions';5import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';6import { AbstractIdentifierNamesGenerator } from './AbstractIdentifierNamesGenerator';7import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';8import { NodeLexicalScopeUtils } from '../../node/NodeLexicalScopeUtils';9@injectable()10export class DictionaryIdentifierNamesGenerator extends AbstractIdentifierNamesGenerator {11 /**12 * @type {IArrayUtils}13 */14 private readonly arrayUtils: IArrayUtils;15 /**16 * @type {Set<string>}17 */18 private identifierNamesSet: Set<string>;19 20 /**21 * @type {IterableIterator<string>}22 */23 private identifiersIterator: IterableIterator<string>;24 /**25 * @param {IRandomGenerator} randomGenerator26 * @param {IOptions} options27 * @param {IArrayUtils} arrayUtils28 */29 public constructor (30 @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,31 @inject(ServiceIdentifiers.IOptions) options: IOptions,32 @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,33 ) {34 super(randomGenerator, options);35 this.arrayUtils = arrayUtils;36 this.identifierNamesSet = new Set(this.getInitialIdentifierNames(this.options.identifiersDictionary));37 this.identifiersIterator = this.identifierNamesSet.values();38 }39 /**40 * @param {string} identifierName41 * @returns {string | null}42 */43 private static incrementIdentifierName (identifierName: string): string | null {44 let newIdentifierName: string = '';45 let isSuccess: boolean = false;46 for (const character of identifierName) {47 if (!isSuccess && character === character.toUpperCase()) {48 newIdentifierName += character.toLowerCase();49 } else if (!isSuccess && character === character.toLowerCase()) {50 newIdentifierName += character.toUpperCase();51 isSuccess = true;52 } else {53 newIdentifierName += character;54 }55 }56 if (isSuccess) {57 return newIdentifierName;58 }59 return null;60 }61 public generateNext (): string {62 const identifierName: string = this.generateNewDictionaryName();63 this.preserveName(identifierName);64 return identifierName;65 }66 /**67 * @returns {string}68 */69 public generateForGlobalScope (): string {70 const prefix: string = this.options.identifiersPrefix ?71 `${this.options.identifiersPrefix}`72 : '';73 const identifierName: string = this.generateNewDictionaryName((newIdentifierName: string) => {74 const identifierNameWithPrefix: string = `${prefix}${newIdentifierName}`;75 return this.isValidIdentifierName(identifierNameWithPrefix);76 });77 const identifierNameWithPrefix = `${prefix}${identifierName}`;78 this.preserveName(identifierNameWithPrefix);79 return identifierNameWithPrefix;80 }81 /**82 * @param {TNodeWithLexicalScope} lexicalScopeNode83 * @returns {string}84 */85 public generateForLexicalScope (lexicalScopeNode: TNodeWithLexicalScope): string {86 const lexicalScopes: TNodeWithLexicalScope[] = [87 lexicalScopeNode,88 ...NodeLexicalScopeUtils.getLexicalScopes(lexicalScopeNode)89 ];90 const identifierName: string = this.generateNewDictionaryName((newIdentifierName: string) =>91 this.isValidIdentifierNameInLexicalScopes(newIdentifierName, lexicalScopes)92 );93 this.preserveNameForLexicalScope(identifierName, lexicalScopeNode);94 return identifierName;95 }96 /**97 * @param {string} label98 * @returns {string}99 */100 public generateForLabel (label: string): string {101 return this.generateNewDictionaryName();102 }103 /**104 * @param {(newIdentifierName: string) => boolean} validationFunction105 * @returns {string}106 */107 private generateNewDictionaryName (validationFunction?: (newIdentifierName: string) => boolean): string {108 const generateNewDictionaryName = (): string => {109 if (!this.identifierNamesSet.size) {110 throw new Error('Too many identifiers in the code, add more words to identifiers dictionary');111 }112 const iteratorResult: IteratorResult<string> = this.identifiersIterator.next();113 if (!iteratorResult.done) {114 const identifierName: string = iteratorResult.value;115 const isValidIdentifierName = validationFunction?.(identifierName)116 ?? this.isValidIdentifierName(identifierName);117 if (!isValidIdentifierName) {118 return generateNewDictionaryName();119 }120 return iteratorResult.value;121 }122 this.identifierNamesSet = new Set(this.getIncrementedIdentifierNames([...this.identifierNamesSet]));123 this.identifiersIterator = this.identifierNamesSet.values();124 return generateNewDictionaryName();125 };126 return generateNewDictionaryName();127 }128 /**129 * @param {string[]} identifierNames130 * @returns {string[]}131 */132 private getInitialIdentifierNames (identifierNames: string[]): string[] {133 const formattedIdentifierNames: string[] = identifierNames134 .filter(Boolean)135 .map((identifierName: string) => identifierName.toLowerCase());136 return this.arrayUtils.shuffle(formattedIdentifierNames);137 }138 /**139 * @param {string[]} identifierNames140 * @returns {string[]}141 */142 private getIncrementedIdentifierNames (identifierNames: string[]): string[] {143 const formattedIdentifierNames: string[] = [];144 for (const identifierName of identifierNames) {145 const newIdentifierName: string | null = DictionaryIdentifierNamesGenerator146 .incrementIdentifierName(identifierName);147 if (newIdentifierName) {148 formattedIdentifierNames.push(newIdentifierName);149 }150 }151 return this.arrayUtils.shuffle(formattedIdentifierNames);152 }...
buffer.js
Source:buffer.js
1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.default = void 0;6const SPACES_RE = /^[ \t]+$/;7class Buffer {8 constructor(map) {9 this._map = null;10 this._buf = [];11 this._last = "";12 this._queue = [];13 this._position = {14 line: 1,15 column: 016 };17 this._sourcePosition = {18 identifierName: null,19 line: null,20 column: null,21 filename: null22 };23 this._disallowedPop = null;24 this._map = map;25 }26 get() {27 this._flush();28 const map = this._map;29 const result = {30 code: this._buf.join("").trimRight(),31 map: null,32 rawMappings: map && map.getRawMappings()33 };34 if (map) {35 Object.defineProperty(result, "map", {36 configurable: true,37 enumerable: true,38 get() {39 return this.map = map.get();40 },41 set(value) {42 Object.defineProperty(this, "map", {43 value,44 writable: true45 });46 }47 });48 }49 return result;50 }51 append(str) {52 this._flush();53 const {54 line,55 column,56 filename,57 identifierName,58 force59 } = this._sourcePosition;60 this._append(str, line, column, identifierName, filename, force);61 }62 queue(str) {63 if (str === "\n") {64 while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) {65 this._queue.shift();66 }67 }68 const {69 line,70 column,71 filename,72 identifierName,73 force74 } = this._sourcePosition;75 this._queue.unshift([str, line, column, identifierName, filename, force]);76 }77 _flush() {78 let item;79 while (item = this._queue.pop()) this._append(...item);80 }81 _append(str, line, column, identifierName, filename, force) {82 if (this._map && str[0] !== "\n") {83 this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename, force);84 }85 this._buf.push(str);86 this._last = str[str.length - 1];87 for (let i = 0; i < str.length; i++) {88 if (str[i] === "\n") {89 this._position.line++;90 this._position.column = 0;91 } else {92 this._position.column++;93 }94 }95 }96 removeTrailingNewline() {97 if (this._queue.length > 0 && this._queue[0][0] === "\n") {98 this._queue.shift();99 }100 }101 removeLastSemicolon() {102 if (this._queue.length > 0 && this._queue[0][0] === ";") {103 this._queue.shift();104 }105 }106 endsWith(suffix) {107 if (suffix.length === 1) {108 let last;109 if (this._queue.length > 0) {110 const str = this._queue[0][0];111 last = str[str.length - 1];112 } else {113 last = this._last;114 }115 return last === suffix;116 }117 const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, "");118 if (suffix.length <= end.length) {119 return end.slice(-suffix.length) === suffix;120 }121 return false;122 }123 hasContent() {124 return this._queue.length > 0 || !!this._last;125 }126 exactSource(loc, cb) {127 this.source("start", loc, true);128 cb();129 this.source("end", loc);130 this._disallowPop("start", loc);131 }132 source(prop, loc, force) {133 if (prop && !loc) return;134 this._normalizePosition(prop, loc, this._sourcePosition, force);135 }136 withSource(prop, loc, cb) {137 if (!this._map) return cb();138 const originalLine = this._sourcePosition.line;139 const originalColumn = this._sourcePosition.column;140 const originalFilename = this._sourcePosition.filename;141 const originalIdentifierName = this._sourcePosition.identifierName;142 this.source(prop, loc);143 cb();144 if ((!this._sourcePosition.force || this._sourcePosition.line !== originalLine || this._sourcePosition.column !== originalColumn || this._sourcePosition.filename !== originalFilename) && (!this._disallowedPop || this._disallowedPop.line !== originalLine || this._disallowedPop.column !== originalColumn || this._disallowedPop.filename !== originalFilename)) {145 this._sourcePosition.line = originalLine;146 this._sourcePosition.column = originalColumn;147 this._sourcePosition.filename = originalFilename;148 this._sourcePosition.identifierName = originalIdentifierName;149 this._sourcePosition.force = false;150 this._disallowedPop = null;151 }152 }153 _disallowPop(prop, loc) {154 if (prop && !loc) return;155 this._disallowedPop = this._normalizePosition(prop, loc);156 }157 _normalizePosition(prop, loc, targetObj, force) {158 const pos = loc ? loc[prop] : null;159 if (targetObj === undefined) {160 targetObj = {161 identifierName: null,162 line: null,163 column: null,164 filename: null,165 force: false166 };167 }168 const origLine = targetObj.line;169 const origColumn = targetObj.column;170 const origFilename = targetObj.filename;171 targetObj.identifierName = prop === "start" && loc && loc.identifierName || null;172 targetObj.line = pos ? pos.line : null;173 targetObj.column = pos ? pos.column : null;174 targetObj.filename = loc && loc.filename || null;175 if (force || targetObj.line !== origLine || targetObj.column !== origColumn || targetObj.filename !== origFilename) {176 targetObj.force = force;177 }178 return targetObj;179 }180 getCurrentColumn() {181 const extra = this._queue.reduce((acc, item) => item[0] + acc, "");182 const lastIndex = extra.lastIndexOf("\n");183 return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex;184 }185 getCurrentLine() {186 const extra = this._queue.reduce((acc, item) => item[0] + acc, "");187 let count = 0;188 for (let i = 0; i < extra.length; i++) {189 if (extra[i] === "\n") count++;190 }191 return this._position.line + count;192 }193}...
no-alert.js
Source:no-alert.js
1/**2 * @fileoverview Rule to flag use of alert, confirm, prompt3 * @author Nicholas C. Zakas4 * @copyright 2015 Mathias Schreck5 * @copyright 2013 Nicholas C. Zakas6 */7"use strict";8//------------------------------------------------------------------------------9// Helpers10//------------------------------------------------------------------------------11/**12 * Checks if the given name is a prohibited identifier.13 * @param {string} name The name to check14 * @returns {boolean} Whether or not the name is prohibited.15 */16function isProhibitedIdentifier(name) {17 return /^(alert|confirm|prompt)$/.test(name);18}19/**20 * Reports the given node and identifier name.21 * @param {RuleContext} context The ESLint rule context.22 * @param {ASTNode} node The node to report on.23 * @param {string} identifierName The name of the identifier.24 * @returns {void}25 */26function report(context, node, identifierName) {27 context.report(node, "Unexpected {{name}}.", { name: identifierName });28}29/**30 * Returns the property name of a MemberExpression.31 * @param {ASTNode} memberExpressionNode The MemberExpression node.32 * @returns {string|undefined} Returns the property name if available, undefined else.33 */34function getPropertyName(memberExpressionNode) {35 if (memberExpressionNode.computed) {36 if (memberExpressionNode.property.type === "Literal") {37 return memberExpressionNode.property.value;38 }39 } else {40 return memberExpressionNode.property.name;41 }42}43/**44 * Finds the escope reference in the given scope.45 * @param {Object} scope The scope to search.46 * @param {ASTNode} node The identifier node.47 * @returns {Reference|undefined} Returns the found reference or undefined if none were found.48 */49function findReference(scope, node) {50 var references = scope.references.filter(function (reference) {51 return reference.identifier.range[0] === node.range[0] &&52 reference.identifier.range[1] === node.range[1];53 });54 if (references.length === 1) {55 return references[0];56 }57}58/**59 * Checks if the given identifier name is shadowed in the given global scope.60 * @param {Object} globalScope The global scope.61 * @param {string} identifierName The identifier name to check62 * @returns {boolean} Whether or not the name is shadowed globally.63 */64function isGloballyShadowed(globalScope, identifierName) {65 return globalScope.variables.some(function (variable) {66 return variable.name === identifierName && variable.defs.length > 0;67 });68}69/**70 * Checks if the given identifier node is shadowed in the given scope.71 * @param {Object} scope The current scope.72 * @param {Object} globalScope The global scope.73 * @param {string} node The identifier node to check74 * @returns {boolean} Whether or not the name is shadowed.75 */76function isShadowed(scope, globalScope, node) {77 var reference = findReference(scope, node),78 identifierName = node.name;79 if (reference) {80 if (reference.resolved || isGloballyShadowed(globalScope, identifierName)) {81 return true;82 }83 }84 return false;85}86/**87 * Checks if the given identifier node is a ThisExpression in the global scope or the global window property.88 * @param {Object} scope The current scope.89 * @param {Object} globalScope The global scope.90 * @param {string} node The identifier node to check91 * @returns {boolean} Whether or not the node is a reference to the global object.92 */93function isGlobalThisReferenceOrGlobalWindow(scope, globalScope, node) {94 if (scope.type === "global" && node.type === "ThisExpression") {95 return true;96 } else if (node.name === "window") {97 return !isShadowed(scope, globalScope, node);98 }99 return false;100}101//------------------------------------------------------------------------------102// Rule Definition103//------------------------------------------------------------------------------104module.exports = function(context) {105 var globalScope;106 return {107 "Program": function () {108 globalScope = context.getScope();109 },110 "CallExpression": function(node) {111 var callee = node.callee,112 identifierName,113 currentScope = context.getScope();114 // without window.115 if (callee.type === "Identifier") {116 identifierName = callee.name;117 if (!isShadowed(currentScope, globalScope, callee) && isProhibitedIdentifier(callee.name)) {118 report(context, node, identifierName);119 }120 } else if (callee.type === "MemberExpression" && isGlobalThisReferenceOrGlobalWindow(currentScope, globalScope, callee.object)) {121 identifierName = getPropertyName(callee);122 if (isProhibitedIdentifier(identifierName)) {123 report(context, node, identifierName);124 }125 }126 }127 };128};...
Using AI Code Generation
1var storybook = require('storybook-root');2var name = storybook.identifierName();3console.log(name);4var storybook = require('storybook-root');5var name = storybook.identifierName();6console.log(name);7var storybook = require('storybook-root');8var name = storybook.identifierName();9console.log(name);10var storybook = require('storybook-root');11var name = storybook.identifierName();12console.log(name);13var storybook = require('storybook-root');14var name = storybook.identifierName();15console.log(name);16var storybook = require('storybook-root');17var name = storybook.identifierName();18console.log(name);19var storybook = require('storybook-root');20var name = storybook.identifierName();21console.log(name);22var storybook = require('storybook-root');23var name = storybook.identifierName();24console.log(name);25var storybook = require('storybook-root');26var name = storybook.identifierName();27console.log(name);28var storybook = require('storybook-root');29var name = storybook.identifierName();30console.log(name);31var storybook = require('storybook-root');32var name = storybook.identifierName();33console.log(name);34var storybook = require('storybook-root');35var name = storybook.identifierName();36console.log(name);37var storybook = require('storybook-root');38var name = storybook.identifierName();
Using AI Code Generation
1var identifierName = require('storybook-root').identifierName;2console.log(identifierName);3module.exports = {4};5{6}7{8 "dependencies": {9 }10}11{12 "dependencies": {13 }14}15module.exports = {16};17{18}19{20 "dependencies": {21 }22}23{24 "dependencies": {25 }26}27module.exports = {28};29{30}31{32 "dependencies": {33 }34}35{
Using AI Code Generation
1import { identifierName } from 'storybook-root';2identifierName();3import { identifierName } from 'storybook-root';4identifierName();5import { identifierName } from 'storybook-root';6identifierName();7import { identifierName } from 'storybook-root';8identifierName();9import { identifierName } from 'storybook-root';10identifierName();11import { identifierName } from 'storybook-root';12identifierName();13import { identifierName } from 'storybook-root';14identifierName();15import { identifierName } from 'storybook-root';16identifierName();17import { identifierName } from 'storybook-root';18identifierName();19import { identifierName } from 'storybook-root';20identifierName();21import { identifierName } from 'storybook-root';22identifierName();23import { identifierName } from 'storybook-root';24identifierName();
Using AI Code Generation
1var storybook = require('storybook-root');2var identifierName = storybook.identifierName;3identifierName('test');4var storybook = require('storybook-root');5var identifierName = storybook.identifierName;6identifierName('test');7var storybook = require('storybook-root');8var identifierName = storybook.identifierName;9identifierName('test');10var storybook = require('storybook-root');11var identifierName = storybook.identifierName;12identifierName('test');13var storybook = require('storybook-root');14var identifierName = storybook.identifierName;15identifierName('test');16var storybook = require('storybook-root');17var identifierName = storybook.identifierName;18identifierName('test');19var storybook = require('storybook-root');20var identifierName = storybook.identifierName;21identifierName('test');22var storybook = require('storybook-root');23var identifierName = storybook.identifierName;24identifierName('test');25var storybook = require('storybook-root');26var identifierName = storybook.identifierName;27identifierName('test');28var storybook = require('storybook-root');29var identifierName = storybook.identifierName;30identifierName('test');31var storybook = require('storybook-root');32var identifierName = storybook.identifierName;33identifierName('test');34var storybook = require('storybook-root');35var identifierName = storybook.identifierName;36identifierName('test');
Using AI Code Generation
1const identifierName = require('storybook-root').identifierName;2console.log(identifierName);3const identifierName = require('storybook-root').identifierName;4console.log(identifierName);5const identifierName = require('storybook-root').identifierName;6console.log(identifierName);7const identifierName = require('storybook-root').identifierName;8console.log(identifierName);9const identifierName = require('storybook-root').identifierName;10console.log(identifierName);11const identifierName = require('storybook-root').identifierName;12console.log(identifierName);13const identifierName = require('storybook-root').identifierName;14console.log(identifierName);15const identifierName = require('storybook-root').identifierName;16console.log(identifierName);17const identifierName = require('storybook-root').identifierName;18console.log(identifierName);19const identifierName = require('storybook-root').identifierName;20console.log(identifierName);21const identifierName = require('storybook-root').identifierName;22console.log(identifierName);23const identifierName = require('storybook-root').identifierName;24console.log(identifierName);25const identifierName = require('storybook-root').identifierName;26console.log(identifierName);
Using AI Code Generation
1import { identifierName } from "storybook-root-alias";2const path = identifierName("path");3console.log(path);4import { identifierName } from "storybook-root-alias";5const path = identifierName("path");6console.log(path);7import { identifierName } from "storybook-root-alias";8const path = identifierName("path");9console.log(path);10import { identifierName } from "storybook-root-alias";11const path = identifierName("path");12console.log(path);13import { identifierName } from "storybook-root-alias";14const path = identifierName("path");15console.log(path);16import { identifierName } from "storybook-root-alias";17const path = identifierName("path");18console.log(path);19import { identifierName } from "storybook-root-alias";20const path = identifierName("path");21console.log(path);22import { identifierName } from "storybook-root-alias";23const path = identifierName("path");24console.log(path);25import { identifierName } from "storybook-root-alias";26const path = identifierName("path");27console.log(path);28import { identifierName } from "storybook-root-alias";29const path = identifierName("path");30console.log(path);31import { identifierName } from "
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!!