Skip to content

Commit

Permalink
Implement module
Browse files Browse the repository at this point in the history
ES6 module for typescipt and UMD for Javascript
  • Loading branch information
ipanardian committed Jan 1, 2017
1 parent 251c821 commit 9da3302
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-object-assign"]
"plugins": ["transform-object-assign","transform-es2015-modules-umd"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
.vscode
src/browser-notif.js
src/Test.ts
example/
42 changes: 36 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/BrowserNotif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface PermissionInterface {
Denied: string
}

class BrowserNotif implements BrowserNotifInterface
export default class BrowserNotif implements BrowserNotifInterface
{
/**
* Title notification
Expand Down Expand Up @@ -119,6 +119,7 @@ class BrowserNotif implements BrowserNotifInterface
console.warn('This browser does not support system notifications');
}

// Navigator.serviceWorker.register('sw.js')
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
"src/BrowserNotif.ts"
"include": [
"src/*"
],
"compileOnSave": false,
"compilerOptions": {
Expand Down

0 comments on commit 9da3302

Please sign in to comment.