How to use normalizedFileName method in storybook-root

Best JavaScript code snippet using storybook-root

FileTransferApplicationService.js

Source:FileTransferApplicationService.js Github

copy

Full Screen

1/// FOURJS_START_COPYRIGHT(D,2015)2/// Property of Four Js*3/// (c) Copyright Four Js 2015, 2019. All Rights Reserved.4/// * Trademark of Four Js Development Tools Europe Ltd5/// in the United States and elsewhere6/// 7/// This file can be modified by licensees according to the8/// product manual.9/// FOURJS_END_COPYRIGHT10"use strict";11modulum('FileTransferApplicationService', ['ApplicationServiceBase', 'ApplicationServiceFactory'],12 function(context, cls) {13 /**14 * Base class of application scoped services15 * @class FileTransferApplicationService16 * @memberOf classes17 * @extends classes.ApplicationServiceBase18 */19 cls.FileTransferApplicationService = context.oo.Class(cls.ApplicationServiceBase, function($super) {20 return /** @lends classes.FileTransferApplicationService.prototype */ {21 __name: "FileTransferApplicationService",22 /**23 * @type {Object<string, Array<FilePickerWidget>>}24 */25 _fileChoosers: null,26 /**27 * @inheritDoc28 */29 constructor: function(app) {30 $super.constructor.call(this, app);31 this._fileChoosers = {};32 },33 /**34 * Handler raised on file pick35 * @param callback36 * @param errorCallback37 * @param event38 * @param src39 * @param data40 * @private41 */42 _whenFileSelectionChanged: function(callback, errorCallback, event, src, data) {43 var hasData = false;44 var normalizedFileName = "";45 if (data) {46 if (Array.isArray(data)) {47 if (data.length) {48 hasData = true;49 for (var i = 0; i < data.length; i++) {50 // normalize() converts 2 combined diacritical marks into 1 (ex: é encoded as e')51 // For exemple under Safari a file with name 'Qualité.pdf' has a length of 12 while under52 // chrome length will be 11 because of the special accent char : é53 // for this reason we need to normalize our file name.54 // ! IE11 doesn't support normalize.55 var fileName = data[i];56 normalizedFileName = fileName.normalize ? fileName.normalize() : fileName;57 this._fileChoosers[normalizedFileName] = this._fileChoosers[normalizedFileName] || [];58 this._fileChoosers[normalizedFileName].push(src);59 src._processing = true;60 }61 } else {62 src.destroy();63 }64 } else {65 hasData = true;66 // cf previous comment of normalize()67 normalizedFileName = data.normalize ? data.normalize() : data;68 this._fileChoosers[normalizedFileName] = this._fileChoosers[normalizedFileName] || [];69 this._fileChoosers[normalizedFileName].push(src);70 src._processing = true;71 }72 if (hasData) {73 src.when(context.constants.widgetEvents.destroyed, this._onFilePickerDestroyed.bind(this, src), true);74 }75 callback(data);76 } else {77 src.destroy();78 callback("");79 }80 },81 /**82 * manage openFile frontcall83 * @param options84 * @param callback85 * @param errorCallback86 */87 openFile: function(options, callback, errorCallback) {88 var filePicker = cls.WidgetFactory.createWidget("FilePicker", {89 appHash: this._application.applicationHash90 });91 this._application.layout.afterLayout(function() {92 filePicker.resizeHandler();93 });94 this._application.getUI().getWidget().getElement().appendChild(filePicker.getElement());95 filePicker.setExtension(this._extractExtensions(options && options.wildcards || ""));96 filePicker.setCaption(options && options.caption || "");97 filePicker.show();98 filePicker.whenFileSelectionChanged(this._whenFileSelectionChanged.bind(this, callback, errorCallback));99 },100 /**101 * manage openFiles frontcall102 * @param options103 * @param callback104 * @param errorCallback105 */106 openFiles: function(options, callback, errorCallback) {107 var filePicker = cls.WidgetFactory.createWidget("FilePicker", {108 appHash: this._application.applicationHash109 });110 this._application.layout.afterLayout(function() {111 filePicker.resizeHandler();112 });113 this._application.getUI().getWidget().getElement().appendChild(filePicker.getElement());114 filePicker.setExtension(this._extractExtensions(options && options.wildcards || ""));115 filePicker.setCaption(options && options.caption || "");116 filePicker.allowMultipleFiles(true);117 filePicker.show();118 filePicker.whenFileSelectionChanged(this._whenFileSelectionChanged.bind(this, callback, errorCallback));119 },120 /**121 * getFile method executed on getfile frontcall call122 * @param options123 * @param callback124 * @param errorCallback125 */126 getFile: function(options, callback, errorCallback) {127 var filePicker;128 // cf previous comment of normalize() in _whenFileSelectionChanged function definition129 var normalizedFileName = options.filename.normalize ? options.filename.normalize() : options.filename;130 var onSuccess = function() {131 if (filePicker._processing) {132 this._application.getMenu("uploadStatus").setIdle();133 }134 callback();135 filePicker.freeFile(normalizedFileName, true);136 if (this._fileChoosers[normalizedFileName]) {137 this._fileChoosers[normalizedFileName].remove(filePicker);138 }139 }.bind(this),140 onError = function() {141 if (filePicker._processing) {142 this._application.getMenu("uploadStatus").setIdle();143 }144 errorCallback();145 filePicker.freeFile(normalizedFileName, true);146 if (this._fileChoosers[normalizedFileName]) {147 this._fileChoosers[normalizedFileName].remove(filePicker);148 }149 }.bind(this),150 onFile = function(file) {151 if (!file) {152 onError();153 } else {154 this._application.getMenu("uploadStatus").setProcessing();155 var url = options.fileTransferUrl;156 filePicker.send(file, url, onSuccess, onError);157 }158 }.bind(this);159 if (this._fileChoosers[normalizedFileName] && this._fileChoosers[normalizedFileName].length) {160 filePicker = this._fileChoosers[normalizedFileName].shift();161 onFile(normalizedFileName);162 } else {163 filePicker = cls.WidgetFactory.createWidget("FilePicker", {164 appHash: this._application.applicationHash165 });166 this._application.layout.afterLayout(function() {167 filePicker.resizeHandler();168 });169 this._application.getUI().getWidget().getElement().appendChild(filePicker.getElement());170 filePicker.setExtension("." + normalizedFileName.split('.').pop());171 filePicker.show();172 filePicker.whenFileSelectionChanged(this._whenFileSelectionChanged.bind(this, onFile, onError));173 }174 },175 /**176 * @inheritDoc177 */178 destroy: function() {179 var destroyable = [],180 keys = Object.keys(this._fileChoosers),181 len = keys.length,182 k = 0,183 i = 0;184 for (; k < len; k++) {185 while (this._fileChoosers[k] && this._fileChoosers[k][i]) {186 if (!destroyable.contains(this._fileChoosers[k][i])) {187 destroyable.push(this._fileChoosers[k][i]);188 }189 i++;190 }191 }192 len = destroyable.length;193 for (k = 0; k < len; k++) {194 destroyable[k].destroy();195 }196 $super.destroy.call(this);197 },198 /**199 * free resources when a file picker is destroyed200 * @param {classes.FilePickerWidget} picker201 * @private202 */203 _onFilePickerDestroyed: function(picker) {204 var files = picker && picker.getAvailableFiles();205 if (files) {206 for (var i = 0; i < files.length; i++) {207 if (this._fileChoosers[files[i]]) {208 this._fileChoosers[files[i]].remove(picker);209 }210 }211 }212 },213 /**214 * format extensions215 * @param {string} raw216 * @return {string}217 * @private218 */219 _extractExtensions: function(raw) {220 var regex = /[^\s]*(\.[^.\s]+)/g,221 m, res = [];222 while ((m = regex.exec(raw)) !== null) {223 var ext = m[1];224 if (ext === ".*") {225 res.length = 0;226 break;227 }228 res.push(ext);229 }230 return res.join(",") || "";231 }232 };233 });234 cls.ApplicationServiceFactory.register("FileTransfer", cls.FileTransferApplicationService);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1'use strict';2const path = require('path');3const {fileURLToPath} = require('url');4const resolveCwd = require('resolve-cwd');5const pkgDir = require('pkg-dir');6module.exports = filename => {7 const normalizedFilename = filename.startsWith('file://') ? fileURLToPath(filename) : filename;8 const globalDir = pkgDir.sync(path.dirname(normalizedFilename));9 const relativePath = path.relative(globalDir, normalizedFilename);10 const pkg = require(path.join(globalDir, 'package.json'));11 const localFile = resolveCwd.silent(path.join(pkg.name, relativePath));12 const localNodeModules = path.join(process.cwd(), 'node_modules');13 const filenameInLocalNodeModules = !path.relative(localNodeModules, normalizedFilename).startsWith('..') &&14 // On Windows, if `localNodeModules` and `normalizedFilename` are on different partitions, `path.relative()` returns the value of `normalizedFilename`, resulting in `filenameInLocalNodeModules` incorrectly becoming `true`.15 path.parse(localNodeModules).root === path.parse(normalizedFilename).root;16 // Use `path.relative()` to detect local package installation,17 // because __filename's case is inconsistent on Windows18 // Can use `===` when targeting Node.js 819 // See https://github.com/nodejs/node/issues/662420 return !filenameInLocalNodeModules && localFile && path.relative(localFile, normalizedFilename) !== '' && require(localFile);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const rootPath = path.resolve(__dirname, '../');3module.exports = {4 webpackFinal: async (config) => {5 config.resolve.alias['storybook-root-alias'] = rootPath;6 return config;7 },8};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { normalizedFileName } from 'storybook-root-alias';2console.log(normalizedFileName('test.js'));3import { normalizedFileName } from 'storybook-root-alias';4console.log(normalizedFileName('src/components/test.js'));5import { normalizedFileName } from 'storybook-root-alias';6console.log(normalizedFileName('/Users/username/Projects/my-project/src/components/test.js'));7import { normalizedFileName } from 'storybook-root-alias';8console.log(normalizedFileName('src/components/test.js'));9import { normalizedFileName } from 'storybook-root-alias';10console.log(normalizedFileName('/Users/username/Projects/my-project/src/components/test.js'));11import { normalizedFileName } from 'storybook-root-alias';12console.log(normalizedFileName('src/components/test.js'));13import { normalizedFileName } from 'storybook-root-alias';14console.log(normalizedFileName('/Users/username/Projects/my-project/src/components/test.js'));15import { normalizedFileName } from 'storybook-root-alias';16console.log(normalizedFileName('src/components/test.js'));17import { normalizedFileName } from 'storybook-root-alias';18console.log(normalizedFileName('/Users/username/Projects

Full Screen

Using AI Code Generation

copy

Full Screen

1const rootAlias = require('storybook-root-alias');2const normalizedFileName = rootAlias.getNormalizedFileName(__filename);3console.log(normalizedFileName);4const rootAlias = require('storybook-root-alias');5const normalizedFileName = rootAlias.getNormalizedFileName(__filename);6console.log(normalizedFileName);7const rootAlias = require('storybook-root-alias');8const normalizedFileName = rootAlias.getNormalizedFileName(__filename);9console.log(normalizedFileName);10const rootAlias = require('storybook-root-alias');11const normalizedFileName = rootAlias.getNormalizedFileName(__filename);12console.log(normalizedFileName);13const rootAlias = require('storybook-root-alias');14const normalizedFileName = rootAlias.getNormalizedFileName(__filename);15console.log(normalizedFileName);16const rootAlias = require('storybook-root-alias');17const normalizedFileName = rootAlias.getNormalizedFileName(__filename);18console.log(normalizedFileName);19const rootAlias = require('storybook-root-alias');20const normalizedFileName = rootAlias.getNormalizedFileName(__filename);21console.log(normalizedFileName);22const rootAlias = require('storybook-root-alias');23const normalizedFileName = rootAlias.getNormalizedFileName(__filename);24console.log(normalizedFileName);

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const rootRequire = require('storybook-root-require');3const pathToTestFile = rootRequire('src/testFile.js');4console.log(pathToTestFile);5const pathToTestFile = rootRequire('./src/testFile.js');6console.log(pathToTestFile);7const pathToTestFile = rootRequire('../storybook-root-require/src/testFile.js');8console.log(pathToTestFile);9rootRequire(path)

Full Screen

Using AI Code Generation

copy

Full Screen

1import { normalizedFileName } from 'storybook-root-require';2import { normalizedFileNameFromStorybook } from 'storybook-root-require';3import { configure } from '@storybook/react';4import 'storybook-root-require/register';5configure(require.context('../src', true, /\.stories\.js$/), module);6import React from 'react';7import { storiesOf } from '@storybook/react';8import { normalizedFileNameFromStorybook } from 'storybook-root-require';9const stories = storiesOf('ComponentName', module);10stories.add('default', () => {11 return <div>{fileName}</div>;12});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { normalizedFileName } from 'storybook-root-alias';2const path = normalizedFileName( __filename );3console.log( path );4{5 "devDependencies": {6 }7}8{9 {10 }11}12require( 'babel-register' );13require( './test.js' );

Full Screen

Using AI Code Generation

copy

Full Screen

1const { normalizedFileName } = require('storybook-root');2console.log(normalizedFileName);3const { normalizedFileName } = require('storybook-root');4console.log(normalizedFileName);5const { normalizedFileName } = require('storybook-root');6console.log(normalizedFileName);7const { normalizedFileName } = require('storybook-root');8console.log(normalizedFileName);9const { normalizedFileName } = require('storybook-root');10console.log(normalizedFileName);11const { normalizedFileName } = require('storybook-root');12console.log(normalizedFileName);13const { normalizedFileName } = require('storybook-root');14console.log(normalizedFileName);

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