next-persist
Advanced tools
Comparing version 1.1.3-alpha.5 to 1.1.3-alpha.6
19
index.js
@@ -1,16 +0,13 @@ | ||
// export { default as getLocalStore} from './src/getLocalStore'; | ||
// export { default as setLocalStore } from './src/setLocalStore'; | ||
// export { default as getCookieStore } from './src/getCookieStore'; | ||
// export { default as setCookieStore } from './src/setCookieStore'; | ||
// export { default as NextPersistWrapper } from './src/NextPersistWrapper' | ||
// module.exports = require('./src/next-persist-cookieStore') | ||
// module.exports = require('./src/next-persist-localStore') | ||
// module.exports = require('./src/NextPersistWrapper') | ||
const getLocalStore = require('./src/getLocalStore'); | ||
const setLocalStore = require('./src/setLocalStore'); | ||
const getCookieProps = require('./src/getCookieProps'); | ||
const getCookieStore = require('./src/getCookieStore'); | ||
const setCookieStore = require('./src/setCookieStore'); | ||
module.exports = { getLocalStore, setLocalStore, getCookieStore, setCookieStore }; | ||
module.exports = { | ||
getLocalStore, | ||
setLocalStore, | ||
getCookieProps, | ||
getCookieStore, | ||
setCookieStore, | ||
}; |
{ | ||
"name": "next-persist", | ||
"version": "1.1.3-alpha.5", | ||
"version": "1.1.3-alpha.6", | ||
"description": "Bridging the gap between client-side persistence and server-side rendering", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,18 +1,18 @@ | ||
/** | ||
* ************************************ | ||
* | ||
* @module next-persist | ||
* @author most-js | ||
* @description function to get cookies containing state | ||
* | ||
* ************************************ | ||
*/ | ||
const Cookie = require('js-cookie'); | ||
const cookie = require('cookie'); | ||
function getCookieStore (...args) { | ||
// if application is running client-side, parse and return cookie from browser | ||
if (typeof args[0] === 'string') { | ||
const cookieName = args[0]; | ||
const state = args[1]; | ||
const stateFromCookie = Cookie.get(cookieName); | ||
return stateFromCookie ? JSON.parse(stateFromCookie) : state; | ||
} // if application is running server-side, parse and return cooking from request body | ||
else { | ||
const req = args[0].ctx.req; | ||
return cookie.parse(req.headers.cookie || ''); | ||
} | ||
}; | ||
function getCookieStore(key, state) { | ||
const stateFromCookie = Cookie.get(key); | ||
return stateFromCookie ? JSON.parse(stateFromCookie) : state; | ||
} | ||
module.exports = getCookieStore; | ||
module.exports = getCookieStore; |
@@ -1,2 +0,12 @@ | ||
function getLocalStore (key, state) { | ||
/** | ||
* ************************************ | ||
* | ||
* @module next-persist | ||
* @author most-js | ||
* @description function to get localStorage containing state | ||
* | ||
* ************************************ | ||
*/ | ||
function getLocalStore(key, state) { | ||
// if application is running client-side, localStorage is accessible | ||
@@ -19,4 +29,4 @@ if (typeof window !== 'undefined') { | ||
return state; | ||
}; | ||
} | ||
module.exports = getLocalStore; | ||
module.exports = getLocalStore; |
@@ -15,4 +15,4 @@ /** | ||
import { useSelector } from 'react-redux'; | ||
import { setCookieStore } from './setCookieStore'; | ||
import { setLocalStore } from './setLocalStore'; | ||
import setCookieStore from './setCookieStore'; | ||
import setLocalStore from './setLocalStore'; | ||
@@ -26,5 +26,5 @@ const NextPersistWrapper = (props) => { | ||
if (props.wrapperConfig.method === 'localStorage') { | ||
return setLocalStore; | ||
method = setLocalStore; | ||
} else if (props.wrapperConfig.method === 'cookies') { | ||
return setCookieStore; | ||
method = setCookieStore; | ||
} | ||
@@ -31,0 +31,0 @@ |
@@ -0,4 +1,14 @@ | ||
/** | ||
* ************************************ | ||
* | ||
* @module next-persist | ||
* @author most-js | ||
* @description function to save state to cookies | ||
* | ||
* ************************************ | ||
*/ | ||
const Cookie = require('js-cookie'); | ||
function setCookieStore (cookieConfig, state) { | ||
function setCookieStore(cookieConfig, state) { | ||
const key = Object.keys(cookieConfig)[0]; | ||
@@ -17,4 +27,4 @@ const allowList = Object.values(cookieConfig)[0]; | ||
} | ||
}; | ||
} | ||
module.exports = setCookieStore; | ||
module.exports = setCookieStore; |
@@ -1,2 +0,12 @@ | ||
function setLocalStore (storageConfig, state) { | ||
/** | ||
* ************************************ | ||
* | ||
* @module next-persist | ||
* @author most-js | ||
* @description function to save state to localStorage | ||
* | ||
* ************************************ | ||
*/ | ||
function setLocalStore(storageConfig, state) { | ||
const key = Object.keys(storageConfig)[0]; | ||
@@ -22,4 +32,4 @@ const allowList = Object.values(storageConfig)[0]; | ||
} | ||
}; | ||
} | ||
module.exports = setLocalStore; | ||
module.exports = setLocalStore; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16240
10
174