UNPKG

930 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = getPlatformExtension;
7
8/**
9 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
10 *
11 * This source code is licensed under the MIT license found in the
12 * LICENSE file in the root directory of this source tree.
13 */
14const SUPPORTED_PLATFORM_EXTS = new Set(['android', 'ios', 'native', 'web']); // Extract platform extension: index.ios.js -> ios
15
16function getPlatformExtension(file, platforms) {
17 const last = file.lastIndexOf('.');
18 const secondToLast = file.lastIndexOf('.', last - 1);
19
20 if (secondToLast === -1) {
21 return null;
22 }
23
24 const platform = file.substring(secondToLast + 1, last); // If an overriding platform array is passed, check that first
25
26 if (platforms && platforms.indexOf(platform) !== -1) {
27 return platform;
28 }
29
30 return SUPPORTED_PLATFORM_EXTS.has(platform) ? platform : null;
31}