@joshfarrant/shortcuts-js
Version:
An iOS 12 Shortcuts creator
144 lines • 4.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require("./");
/** @ignore */
const valueMap = [{
// String
builder: (val, key) => {
const typedVal = val;
const item = {
WFItemType: _1.getItemType(typedVal),
WFValue: {
Value: {
string: typedVal,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
},
};
if (key) {
item.WFKey = {
Value: {
string: key,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
};
}
return item;
},
validator: (item) => (typeof item === typeof ''),
}, {
// Object
builder: (val, key) => {
const typedVal = val;
const item = {
WFItemType: _1.getItemType(typedVal),
WFValue: {
Value: exports.buildSerialization(typedVal),
WFSerializationType: 'WFDictionaryFieldValue',
},
};
if (key) {
item.WFKey = {
Value: {
string: key,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
};
}
return item;
},
validator: (item) => (!Array.isArray(item) && Object(item) === item),
}, {
// Array
builder: (val, key) => {
const typedVal = val;
const item = {
WFItemType: _1.getItemType(typedVal),
WFValue: {
Value: typedVal.map((x) => exports.getMatch(x)),
WFSerializationType: 'WFArrayParameterState',
},
};
if (key) {
item.WFKey = {
Value: {
string: key,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
};
}
return item;
},
validator: (item) => (Array.isArray(item)),
}, {
// Number
builder: (val, key) => {
const typedVal = val;
const item = {
WFItemType: _1.getItemType(typedVal),
WFValue: {
Value: {
string: `${typedVal}`,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
},
};
if (key) {
item.WFKey = {
Value: {
string: key,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
};
}
return item;
},
validator: (item) => (typeof item === typeof 0),
}, {
// Boolean
builder: (val, key) => {
const typedVal = val;
const item = {
WFItemType: _1.getItemType(typedVal),
WFValue: {
Value: typedVal,
WFSerializationType: 'WFNumberSubstitutableState',
},
};
if (key) {
item.WFKey = {
Value: {
string: key,
attachmentsByRange: {},
},
WFSerializationType: 'WFTextTokenString',
};
}
return item;
},
validator: (item) => (typeof item === typeof true),
}];
/** @ignore */
exports.getMatch = (val, key) => {
// Find the validator that returns true for this item
const match = valueMap.find(({ validator }) => (validator(val)));
if (!match) {
throw new Error('Invalid value');
}
const { builder, } = match;
return builder(val, key);
};
/** @ignore */
exports.buildSerialization = (data = {}) => ({
Value: {
WFDictionaryFieldValueItems: Object.entries(data).map(([key, val]) => (exports.getMatch(val, key))),
},
WFSerializationType: 'WFDictionaryFieldValue',
});
//# sourceMappingURL=buildSerialization.js.map