Navigation Menu

Skip to content

Commit

Permalink
chore(deps): update
Browse files Browse the repository at this point in the history
  • Loading branch information
Irfan Maulana committed Mar 21, 2019
1 parent 032ccb0 commit 9a414a9
Show file tree
Hide file tree
Showing 9 changed files with 2,408 additions and 1,770 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,11 @@
module.exports = {
root: true,
env: {
browser: true,
node: true
},
parserOptions: {
parser: 'babel-eslint'
},
extends: ['standard']
};
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -61,6 +61,7 @@ typings/
# next.js build output
.next

eslint-report.html
dist/
session-storage.min.js
session-storage.min.js.gz
Expand Down
21 changes: 18 additions & 3 deletions nuxt-storage.js
@@ -1,13 +1,28 @@
import { getData as getDataLocal, setData as setDataLocal } from './src/local-storage';
import { getData as getDataSession, setData as setDataSession } from './src/session-storage';
import {
getData as getDataLocal,
setData as setDataLocal,
removeItem as removeItemLocal,
clear as clearLocal
} from './src/local-storage';

import {
getData as getDataSession,
setData as setDataSession,
removeItem as removeItemSession,
clear as clearSession
} from './src/session-storage';

export default {
localStorage: {
getData: getDataLocal,
setData: setDataLocal,
removeItem: removeItemLocal,
clear: clearLocal
},
sessionStorage: {
getData: getDataSession,
setData: setDataSession,
removeItem: removeItemSession,
clear: clearSession
}
}
};
34 changes: 21 additions & 13 deletions package.json
@@ -1,10 +1,13 @@
{
"name": "nuxt-storage",
"version": "1.0.9",
"version": "1.1.0",
"description": "馃洟 Utilities for easy read and write browser's storage in Nuxt.js project",
"scripts": {
"build": "cross-env NODE_ENV=production ./node_modules/.bin/webpack --progress --hide-modules",
"test": "./node_modules/.bin/jest",
"lint": "eslint --ext .js --ignore-path .gitignore .",
"lint:fix": "eslint --ext .js --ignore-path .gitignore . --fix",
"lint:report": "eslint --ext .js --ignore-path .gitignore . --fix -f html-extended -o eslint-report.html",
"prepublishOnly": "yarn run build"
},
"repository": {
Expand All @@ -26,25 +29,30 @@
"homepage": "https://github.com/mazipan/nuxt-storage#readme",
"main": "dist/nuxt-storage.min.js",
"files": [
"index.js",
"nuxt-storage.js",
"src",
"dist/nuxt-storage.min.js",
"dist/nuxt-storage.min.js.gz",
"local-storage/index.js",
"local-storage/index.js.gz",
"session-storage/index.js",
"session-storage/index.js.gz"
"dist",
"local-storage",
"session-storage"
],
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "23.6.0",
"babel-jest": "24.5.0",
"babel-loader": "^8.0.4",
"compression-webpack-plugin": "^2.0.0",
"copy-webpack-plugin": "4.5.2",
"copy-webpack-plugin": "5.0.1",
"cross-env": "5.2.0",
"jest": "^23.6.0",
"eslint": "^5.13.0",
"eslint-config-standard": "^12.0.0",
"eslint-formatter-html-extended": "^1.0.2",
"eslint-loader": "^2.1.2",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.5.0",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
}
Expand Down
28 changes: 24 additions & 4 deletions src/local-storage.js
@@ -1,8 +1,14 @@
import { __getData, __setData } from './unified-storage';
import { __getData, __setData, __removeItem, __clear } from './unified-storage';

export const getData = (key) => {
function getStorage() {
return 'localStorage' in window && window.localStorage
? window.localStorage
: null;
}

export const getData = key => {
try {
const ls = 'localStorage' in window && window.localStorage ? window.localStorage : null;
const ls = getStorage();
return __getData(ls, key);
} catch (e) {}

Expand All @@ -11,8 +17,22 @@ export const getData = (key) => {

export const setData = (key, value = '', expiryInMinutes = 5) => {
try {
const ls = 'localStorage' in window && window.localStorage ? window.localStorage : null;
const ls = getStorage();
return __setData(ls, key, value, expiryInMinutes);
} catch (e) {}
return null;
};

export const removeItem = key => {
try {
const ls = getStorage();
__removeItem(ls, key);
} catch (e) {}
};

export const clear = () => {
try {
const ls = getStorage();
__clear(ls);
} catch (e) {}
};
28 changes: 24 additions & 4 deletions src/session-storage.js
@@ -1,9 +1,15 @@
import { __getData, __setData } from './unified-storage';
import { __getData, __setData, __removeItem, __clear } from './unified-storage';

export const getData = (key) => {
function getStorage() {
return 'sessionStorage' in window && window.sessionStorage
? window.sessionStorage
: null;
}

export const getData = key => {
if (process.client) {
try {
const ls = 'sessionStorage' in window && window.sessionStorage ? window.sessionStorage : null;
const ls = getStorage();
return __getData(ls, key);
} catch (e) {}
}
Expand All @@ -14,9 +20,23 @@ export const getData = (key) => {
export const setData = (key, value = '', expiryInMinutes = 5) => {
if (process.client) {
try {
const ls = 'sessionStorage' in window && window.sessionStorage ? window.sessionStorage : null;
const ls = getStorage();
return __setData(ls, key, value, expiryInMinutes);
} catch (e) {}
}
return null;
};

export const removeItem = key => {
try {
const ls = getStorage();
__removeItem(ls, key);
} catch (e) {}
};

export const clear = () => {
try {
const ls = getStorage();
__clear(ls);
} catch (e) {}
};
12 changes: 12 additions & 0 deletions src/unified-storage.js
Expand Up @@ -44,3 +44,15 @@ export const __setData = (storage, key, value = '', expiryInMinutes = 5) => {
} catch (e) {}
return null;
};

export const __removeItem = (storage, key) => {
try {
storage.removeItem(key)
} catch (e) {}
};

export const __clear = (storage) => {
try {
storage.clear()
} catch (e) {}
};
1 change: 0 additions & 1 deletion webpack.config.js
@@ -1,5 +1,4 @@
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const CompressionPlugin = require("compression-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
Expand Down

0 comments on commit 9a414a9

Please sign in to comment.