get_platform_extension.js 942 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = getPlatformExtension;
  6. /**
  7. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  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. *
  13. */
  14. const SUPPORTED_PLATFORM_EXTS = {
  15. android: true,
  16. ios: true,
  17. native: true,
  18. web: true
  19. };
  20. // Extract platform extension: index.ios.js -> ios
  21. function getPlatformExtension(file, platforms) {
  22. const last = file.lastIndexOf('.');
  23. const secondToLast = file.lastIndexOf('.', last - 1);
  24. if (secondToLast === -1) {
  25. return null;
  26. }
  27. const platform = file.substring(secondToLast + 1, last);
  28. // If an overriding platform array is passed, check that first
  29. if (platforms && platforms.indexOf(platform) !== -1) {
  30. return platform;
  31. }
  32. return SUPPORTED_PLATFORM_EXTS[platform] ? platform : null;
  33. }