UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

126 lines (124 loc) • 4.64 kB
function fromNativeAuthorizationStatus(status) { if (typeof status === "string") return status; switch (status) { case 0: return "notDetermined"; case 1: return "denied"; case 2: return "authorized"; case 3: return "provisional"; case 4: return "ephemeral"; default: return "notDetermined"; } } const importanceToInt = { none: 0, min: 1, low: 2, default: 3, high: 4, max: 5 }; function toNativeImportance(value) { if (typeof value === "number") { if (!Number.isInteger(value) || value < 0 || value > 5) { throw new Error("Notifications.setChannel: importance must be one of none, min, low, default, high, max"); } return value; } const mapped = importanceToInt[value]; if (mapped === void 0) { throw new Error("Notifications.setChannel: importance must be one of none, min, low, default, high, max"); } return mapped; } function fromNativeImportance(value) { switch (value) { case 0: return "none"; case 1: return "min"; case 2: return "low"; case 3: return "default"; case 4: return "high"; case 5: return "max"; default: return "default"; } } const DEFAULT_ACTION_IDENTIFIER = "expo.modules.notifications.actions.DEFAULT"; function assertCategoryIdentifier(identifier, verb) { if (typeof identifier !== "string" || identifier.length === 0) { throw new Error(`Notifications.${verb}: identifier must be a non-empty string`); } if (identifier.includes(":") || identifier.includes("-")) { throw new Error(`Notifications.${verb}: identifier must not contain ':' or '-'`); } } function assertBooleans(verb, what, value, fields) { if (value === void 0) return; for (const field of fields) { const entry = value[field]; if (entry !== void 0 && typeof entry !== "boolean") { throw new Error(`Notifications.${verb}: ${what}.${field} must be a boolean`); } } } function assertCategoryActions(actions, verb) { if (!Array.isArray(actions)) { throw new Error(`Notifications.${verb}: actions must be an array`); } for (const action of actions) { if (!action || typeof action !== "object") { throw new Error(`Notifications.${verb}: each action must be an object`); } const { identifier, buttonTitle, options, textInput } = action; if (typeof identifier !== "string" || identifier.length === 0) { throw new Error(`Notifications.${verb}: each action needs a non-empty identifier`); } if (typeof buttonTitle !== "string" || buttonTitle.length === 0) { throw new Error(`Notifications.${verb}: each action needs a non-empty buttonTitle`); } if (options !== void 0 && (typeof options !== "object" || options === null)) { throw new Error(`Notifications.${verb}: action options must be an object`); } assertBooleans(verb, "action options", options, [ "isAuthenticationRequired", "isDestructive", "opensAppToForeground" ]); if (textInput !== void 0) { if (typeof textInput !== "object" || textInput === null) { throw new Error(`Notifications.${verb}: action textInput must be an object`); } const { placeholder, submitButtonTitle } = textInput; if (typeof placeholder !== "string" || placeholder.length === 0) { throw new Error(`Notifications.${verb}: action textInput needs a non-empty placeholder`); } if (submitButtonTitle !== void 0 && typeof submitButtonTitle !== "string") { throw new Error(`Notifications.${verb}: action textInput.submitButtonTitle must be a string`); } } } } function assertCategoryOptions(options, verb) { if (options === void 0) return; if (!options || typeof options !== "object") { throw new Error(`Notifications.${verb}: options must be an object`); } assertBooleans(verb, "options", options, [ "allowInCarPlay", "allowAnnouncement", "customDismissAction", "showTitle", "showSubtitle" ]); if (options.categorySummaryFormat !== void 0 && typeof options.categorySummaryFormat !== "string") { throw new Error(`Notifications.${verb}: options.categorySummaryFormat must be a string`); } if (options.previewPlaceholder !== void 0 && typeof options.previewPlaceholder !== "string") { throw new Error(`Notifications.${verb}: options.previewPlaceholder must be a string`); } if (options.intentIdentifiers !== void 0) { if (!Array.isArray(options.intentIdentifiers) || options.intentIdentifiers.some((entry) => typeof entry !== "string")) { throw new Error(`Notifications.${verb}: options.intentIdentifiers must be string[]`); } } } export { DEFAULT_ACTION_IDENTIFIER, assertCategoryActions, assertCategoryIdentifier, assertCategoryOptions, fromNativeAuthorizationStatus, fromNativeImportance, toNativeImportance }; //# sourceMappingURL=types.mjs.map