diff --git a/.babelrc b/.babelrc index c9b759c..4b800f0 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,4 @@ { "presets": ["es2015"], - "plugins": ["transform-object-assign"] + "plugins": ["transform-object-assign","transform-es2015-modules-umd"] } diff --git a/.gitignore b/.gitignore index 4a56926..0839c11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ .vscode src/browser-notif.js +src/Test.ts example/ \ No newline at end of file diff --git a/README.md b/README.md index 5389dc4..189bc4d 100755 --- a/README.md +++ b/README.md @@ -12,32 +12,62 @@ This lets web apps send information to a user even if the application is idle, i [http://ipanardian.github.io/browser-notif](http://ipanardian.github.io/browser-notif) ## Usage +### Typescript ```js -//If you want to explicitly call request permission. Usually this is only called once. +// Import module +import BrowserNotif from './BrowserNotif' + +// If you want to explicitly call request permission. Usually this is only called once. BrowserNotif.requestPermission(p => console.log(p)) // Create instance let notif1 = new BrowserNotif() notif1 - .notify('First Notif', 'Hai there! Nice to meet you.', (n) => console.log('First Notif fired!')) - .click(() => window.open('https://www.ipanardian.com')) + .notify('First Notif', 'Hai there! Nice to meet you.', (n) => { + console.log('First Notif fired!', n) + }) + .click(() => { + window.open('https://www.ipanardian.com') + }) // With options let notif2 = new BrowserNotif({ icon: 'icon.png', lang: 'en-US', - timeout: 10 // How long notif will appear in second + timeout: 10 // How long notif will appear in seconds }) notif2 - .notify('Second Notif', 'Typescript has released new version, chek it out!', (n) => console.log('Second Notif fired!')) - .click(() => window.open('https://www.typescriptlang.org')) + .notify('Second Notif', 'Typescript has released new version, chek it out!', (n) => { + console.log('Second Notif fired!', n) + }) + .click(() => { + window.open('https://www.typescriptlang.org') + }) //close notif pragmatically notif1.close() ``` +### Javascript +In Javascript module is transpiled by Babel into UMD module pattern. Also used Polyfill for ```Object.assign```. +```js +BrowserNotif.default.requestPermission(function(p) { + console.log(p) +}) + +var notif = new BrowserNotif.default({icon: 'icon.png'}) + +notif + .notify('First Notif', 'Hai there! Nice to meet you.', function(n) { + console.log('First Notif fired!', n) + }) + .click(function() { + window.open('https://www.ipanardian.com') + }) +``` + ## Install ``` npm i browser-notif diff --git a/src/BrowserNotif.ts b/src/BrowserNotif.ts index b5b61cf..c10fc9b 100644 --- a/src/BrowserNotif.ts +++ b/src/BrowserNotif.ts @@ -57,7 +57,7 @@ interface PermissionInterface { Denied: string } -class BrowserNotif implements BrowserNotifInterface +export default class BrowserNotif implements BrowserNotifInterface { /** * Title notification @@ -119,6 +119,7 @@ class BrowserNotif implements BrowserNotifInterface console.warn('This browser does not support system notifications'); } + // Navigator.serviceWorker.register('sw.js') } /** diff --git a/tsconfig.json b/tsconfig.json index 33e42b0..6c925ab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { - "files": [ - "src/BrowserNotif.ts" + "include": [ + "src/*" ], "compileOnSave": false, "compilerOptions": {