getPlatformExtension.js 910 B

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