UNPKG

2.49 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function getScheme(config) {
4 return typeof config.scheme === 'string' ? config.scheme : null;
5}
6exports.getScheme = getScheme;
7function setScheme(config, infoPlist) {
8 let scheme = getScheme(config);
9 if (!scheme) {
10 return infoPlist;
11 }
12 return Object.assign(Object.assign({}, infoPlist), { CFBundleURLTypes: [{ CFBundleURLSchemes: [scheme] }] });
13}
14exports.setScheme = setScheme;
15// TODO: update this to work well idempotently!
16function appendScheme(scheme, infoPlist) {
17 if (!scheme) {
18 return infoPlist;
19 }
20 let existingSchemes = infoPlist.CFBundleURLTypes;
21 // No need to append if we don't have any
22 if (!existingSchemes) {
23 return setScheme({ scheme }, infoPlist);
24 }
25 return Object.assign(Object.assign({}, infoPlist), { CFBundleURLTypes: [
26 ...existingSchemes,
27 {
28 CFBundleURLSchemes: [scheme],
29 },
30 ] });
31}
32exports.appendScheme = appendScheme;
33function removeScheme(scheme, infoPlist) {
34 if (!scheme) {
35 return infoPlist;
36 }
37 // No need to remove if we don't have any
38 if (!infoPlist.CFBundleURLTypes) {
39 return infoPlist;
40 }
41 infoPlist.CFBundleURLTypes = infoPlist.CFBundleURLTypes.map(bundleUrlType => {
42 const index = bundleUrlType.CFBundleURLSchemes.indexOf(scheme);
43 if (index > -1) {
44 bundleUrlType.CFBundleURLSchemes.splice(index, 1);
45 if (bundleUrlType.CFBundleURLSchemes.length === 0) {
46 return undefined;
47 }
48 }
49 return bundleUrlType;
50 }).filter(Boolean);
51 return infoPlist;
52}
53exports.removeScheme = removeScheme;
54function hasScheme(scheme, infoPlist) {
55 const existingSchemes = infoPlist.CFBundleURLTypes;
56 if (!Array.isArray(existingSchemes))
57 return false;
58 return existingSchemes.some(({ CFBundleURLSchemes: schemes }) => schemes.includes(scheme));
59}
60exports.hasScheme = hasScheme;
61function getSchemesFromPlist(infoPlist) {
62 if (Array.isArray(infoPlist.CFBundleURLTypes)) {
63 return infoPlist.CFBundleURLTypes.reduce((schemes, { CFBundleURLSchemes }) => {
64 if (Array.isArray(CFBundleURLSchemes)) {
65 return [...schemes, ...CFBundleURLSchemes];
66 }
67 return schemes;
68 }, []);
69 }
70 return [];
71}
72exports.getSchemesFromPlist = getSchemesFromPlist;
73//# sourceMappingURL=Scheme.js.map
\No newline at end of file