UNPKG

1.24 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8/**
9 * Copyright (c) Facebook, Inc. and its affiliates.
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 *
14 */
15const ALLOWED_SCALES = {
16 ios: [1, 2, 3]
17};
18
19function filterPlatformAssetScales(platform, scales) {
20 const whitelist = ALLOWED_SCALES[platform];
21
22 if (!whitelist) {
23 return scales;
24 }
25
26 const result = scales.filter(scale => whitelist.indexOf(scale) > -1);
27
28 if (result.length === 0 && scales.length > 0) {
29 // No matching scale found, but there are some available. Ideally we don't
30 // want to be in this situation and should throw, but for now as a fallback
31 // let's just use the closest larger image
32 const maxScale = whitelist[whitelist.length - 1];
33
34 for (const scale of scales) {
35 if (scale > maxScale) {
36 result.push(scale);
37 break;
38 }
39 } // There is no larger scales available, use the largest we have
40
41
42 if (result.length === 0) {
43 result.push(scales[scales.length - 1]);
44 }
45 }
46
47 return result;
48}
49
50var _default = filterPlatformAssetScales;
51exports.default = _default;
\No newline at end of file