-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b14b24
commit f1e6e1c
Showing
8 changed files
with
2,356 additions
and
8,452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"presets": [ | ||
"@babel/react", | ||
"@babel/env", | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
export { default as WStorage } from './WStorage' | ||
/* eslint-disable no-param-reassign */ | ||
import WStorage from './WStorage' | ||
|
||
const defaultProps = { | ||
name: 'storage', | ||
key: 'wstorage', | ||
storage: 'local', | ||
isSupported: true, | ||
} | ||
|
||
export default { | ||
/** | ||
* Install vue-wstorage plugin | ||
* | ||
* @param {Vue} Vue | ||
* @param {Object} options | ||
*/ | ||
install: (Vue, options = {}) => { | ||
if (typeof process !== 'undefined' && (process.server || process.SERVER_BUILD || (process.env && process.env.VUE_ENV === 'server'))) return | ||
|
||
const { name, key, storage } = options | ||
const props = { | ||
...defaultProps, | ||
name: name || defaultProps.name, | ||
key: key || defaultProps.key, | ||
storage: storage || defaultProps.storage, | ||
} | ||
|
||
try { | ||
const test = 'vue-wstorage-test' | ||
window.localStorage.setItem(test, test) | ||
window.localStorage.removeItem(test) | ||
} catch (e) { | ||
props.isSupported = false | ||
console.error('Local or Session storage is not supported') | ||
} | ||
|
||
Vue[props.name] = new WStorage(props) | ||
Vue.prototype[`$${props.name}`] = new WStorage(props) | ||
}, | ||
/** | ||
* Create vue-wstorage instance | ||
* | ||
* @param {Object} props | ||
*/ | ||
initialize: (props = {}) => new WStorage({ ...defaultProps, ...props }), | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import WStorage from '../src' | ||
|
||
const user = { | ||
name: 'Foo', | ||
surname: 'Demo', | ||
} | ||
|
||
describe('WStorage local', () => { | ||
const $storage = WStorage.initialize() | ||
|
||
beforeEach($storage.session.clean) | ||
|
||
it('Should be set and get value', () => { | ||
$storage.local.set('user', user) | ||
expect($storage.local.get('user')).toEqual(user) | ||
}) | ||
|
||
it('Should be remove value', () => { | ||
$storage.local.set('user', user) | ||
expect($storage.local.get('user')).toEqual(user) | ||
$storage.local.remove('user') | ||
expect($storage.local.get('user')).toEqual(undefined) | ||
}) | ||
|
||
it('Should be clean all value', () => { | ||
$storage.local.set('user', user) | ||
expect($storage.local.get('user')).toEqual(user) | ||
$storage.local.clean() | ||
expect($storage.local.get('user')).toEqual(undefined) | ||
}) | ||
}) | ||
|
||
describe('WStorage session', () => { | ||
const $storage = WStorage.initialize() | ||
|
||
beforeEach($storage.session.clean) | ||
|
||
it('Should be set and get value', () => { | ||
$storage.session.set('user', user) | ||
expect($storage.session.get('user')).toEqual(user) | ||
}) | ||
|
||
it('Should be remove value', () => { | ||
$storage.session.set('user', user) | ||
expect($storage.session.get('user')).toEqual(user) | ||
$storage.session.remove('user') | ||
expect($storage.session.get('user')).toEqual(undefined) | ||
}) | ||
|
||
it('Should be clean all value', () => { | ||
$storage.session.set('user', user) | ||
expect($storage.session.get('user')).toEqual(user) | ||
$storage.session.clean() | ||
expect($storage.session.get('user')).toEqual(undefined) | ||
}) | ||
}) | ||
|
||
describe('WStorage is not supported', () => { | ||
const $storage = WStorage.initialize({ | ||
isSupported: false, | ||
}); | ||
|
||
beforeEach($storage.session.clean); | ||
|
||
it('Should be set and get value returned null', () => { | ||
$storage.session.set('user', user); | ||
expect($storage.session.get('user')).toEqual(null); | ||
}); | ||
|
||
it('Should be remove value returned null', () => { | ||
$storage.session.set('user', user); | ||
expect($storage.session.get('user')).toEqual(null); | ||
$storage.session.remove('user'); | ||
expect($storage.session.get('user')).toEqual(null); | ||
}); | ||
|
||
it('Should be clean all value returned null', () => { | ||
$storage.session.set('user', user); | ||
expect($storage.session.get('user')).toEqual(null); | ||
$storage.session.clean(); | ||
expect($storage.session.get('user')).toEqual(null); | ||
}); | ||
}); | ||
|
||
describe('WStorage install', () => { | ||
let VueMock = () => {} | ||
const $storage = WStorage.install(VueMock); | ||
|
||
it('Should be install library in Vue instance', () => { | ||
expect(VueMock.prototype.$storage).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.