@nativescript/local-notifications
Version:
The Local Notifications plugin allows your app to show notifications when the app is not running.
59 lines • 1.96 kB
JavaScript
// TODO: This could be just an utils file!
export class LocalNotificationsCommon {
static createScheduleEntry(options) {
const entry = Object.assign({}, this.defaults);
// Return entry with defaults if not defined
if (!options) {
entry.id = this.generateNotificationID();
return entry;
}
// Override defaults by options
Object.assign(entry, options);
if (typeof entry.id !== 'number') {
// We need unique IDs in all notifications to be able to persist them without overwriting one another
entry.id = this.generateNotificationID();
}
if (typeof entry.interval === 'string') {
entry.interval = { [entry.interval]: 1 };
}
return entry;
}
static getIntervalData(entry) {
let interval;
let ticks;
if (entry.interval) {
const intervalData = Object.entries(entry.interval)[0];
interval = intervalData[0];
ticks = intervalData[1];
}
else {
interval = null;
ticks = 1;
}
return {
interval,
ticks,
};
}
static generateUUID() {
// Not the best, but it will work. See https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
const s4 = () => Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
}
static generateNotificationID() {
return Math.round((Date.now() + Math.round(100000 * Math.random())) / 1000);
}
}
LocalNotificationsCommon.defaults = {
badge: 0,
interval: null,
ongoing: false,
groupSummary: null,
bigTextStyle: false,
channel: 'Channel',
forceShowWhenInForeground: false,
displayImmediately: false,
};
//# sourceMappingURL=common.js.map