UNPKG

1.06 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * strict
8 * @format
9 */
10'use strict';
11
12function getModuleName(filePath) {
13 // index.js -> index
14 // index.js.flow -> index.js
15 var filename = require("path").basename(filePath, require("path").extname(filePath)); // index.js -> index (when extension has multiple segments)
16
17
18 filename = filename.replace(/(?:\.\w+)+/, ''); // /path/to/button/index.js -> button
19
20 var moduleName = filename === 'index' ? require("path").basename(require("path").dirname(filePath)) : filename; // Example.ios -> Example
21 // Example.product.android -> Example
22
23 moduleName = moduleName.replace(/(?:\.\w+)+/, ''); // foo-bar -> fooBar
24 // Relay compatibility mode splits on _, so we can't use that here.
25
26 moduleName = moduleName.replace(/[^a-zA-Z0-9]+(\w?)/g, function (match, next) {
27 return next.toUpperCase();
28 });
29 return moduleName;
30}
31
32module.exports = getModuleName;
\No newline at end of file