Gathering detailed insights and metrics for vue-cookie-next
Gathering detailed insights and metrics for vue-cookie-next
Gathering detailed insights and metrics for vue-cookie-next
Gathering detailed insights and metrics for vue-cookie-next
A vue 3 plugin for handling browser cookies with typescript support. Load and save cookies within your Vue 3 application
npm install vue-cookie-next
Typescript
Module System
Node Version
NPM Version
68.7
Supply Chain
99.5
Quality
75.8
Maintenance
100
Vulnerability
100
License
TypeScript (48.46%)
JavaScript (44.09%)
Shell (7.45%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
53 Stars
23 Commits
6 Forks
1 Watchers
2 Branches
4 Contributors
Updated on Jun 13, 2024
Latest Version
1.3.0
Package Id
vue-cookie-next@1.3.0
Unpacked Size
47.60 kB
Size
7.35 kB
File Count
10
NPM Version
7.19.0
Node Version
14.15.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
17
A simple Vue 3 plugin for handling browser cookies with typescript support
1<html lang="en"> 2 <head> 3 <script src="https://unpkg.com/vue/dist/vue.js"></script> 4 </head> 5 <body> 6 <div id="app"></div> 7 </body> 8 <script type="module"> 9 import { VueCookieNext } from 'https://unpkg.com/vue-cookie-next@1.0.0/dist/vue-cookie-next.esm-bundler.js' 10 const CookieTest = { 11 mounted() { 12 this.$cookie.setCookie('username', 'user1') 13 console.log(this.$cookie.getCookie('username')) 14 }, 15 } 16 Vue.createApp(CookieTest).use(VueCookieNext).mount('#app') 17 </script> 18</html>
npm install vue-cookie-next
//or
yarn add vue-cookie-next
1import { createApp } from 'vue' 2import { VueCookieNext } from 'vue-cookie-next' 3 4import App from 'App.vue' 5const app = createApp(App) 6app.use(VueCookieNext) 7app.mount('#app') 8 9// set default config 10VueCookieNext.config({ expire: '7d' }) 11 12// set global cookie 13VueCookieNext.setCookie('theme', 'default') 14VueCookieNext.setCookie('hover-time', { expire: '1s' })
1import { defineComponent } from 'vue' 2import { useCookie } from 'vue-cookie-next' 3 4defineComponent({ 5 setup() { 6 const cookie = useCookie() 7 cookie.setCookie('theme', 'dark') 8 cookie.removeCookie('hover-time') 9 }, 10});
syntax format: [this | VueCookieNext].$cookie.[method]
1VueCookieNext.config({ 2 expire: '1d', 3 path: '/', 4 domain: '', 5 secure: '', 6 sameSite: '', 7}) 8// default: expireTimes = 1d, path = '/', domain = '', secure = '', sameSite = 'Lax'
1this.$cookie.setCookie(keyName, value, { 2 expire: '1d', 3 path: '/', 4 domain: '', 5 secure: '', 6 sameSite: '', 7}) //return this
1this.$cookie.getCookie(keyName) // return value
1this.$cookie.removeCookie(keyName, { 2 path: '/', 3 domain: '', 4}) // return this | false if key not found
cookie name
1this.$cookie.isCookieAvailable(keyName) // return false or true
cookie name
1this.$cookie.keys() // return a array string
1import { VueCookieNext } from 'vue-cookie-next'
2// 30 day after, expire
3VueCookieNext.config({ expire: '30d' })
4
5// set secure, only https works
6VueCookieNext.config({ expire: '7d', secure: true })
7
8// 2019-03-13 expire
9VueCookieNext.config({ expire: new Date(2019, 03, 13).toUTCString() })
10
11// 30 day after, expire, '' current path , browser default
12VueCookieNext.config({ expire: 60 * 60 * 24 * 30 })
1var user = { 2 user_id: 1, 3 name: 'Ben', 4 session: '75442486-0878-440c-9db1-a7006c25a39f', 5 session_start_time: new Date(), 6} 7 8this.$cookie.setCookie('user', user) 9// print user name 10console.log(this.$cookie.getCookieCookie('user').name)
Suppose the current time is : Sat, 11 Mar 2017 12:25:57 GMT
Following equivalence: 1 day after, expire
Support chaining sets together
1// default expire time: 1 day 2this.$cookie 3 .setCookie('user_session', '75442486-0878-440c-9db1-a7006c25a39f') 4 // number + d , ignore case 5 .setCookie('user_session', '75442486-0878-440c-9db1-a7006c25a39f', { 6 expire: '1d', 7 }) 8 .setCookie('user_session', '75442486-0878-440c-9db1-a7006c25a39f', { 9 expire: '1D', 10 }) 11 // Base of second 12 .setCookie('user_session', '75442486-0878-440c-9db1-a7006c25a39f', { 13 expire: 60 * 60 * 24, 14 }) 15 // input a Date, + 1day 16 .setCookie('user_session', '75442486-0878-440c-9db1-a7006c25a39f', { 17 expire: new Date(2017, 03, 12), 18 }) 19 // input a date string, + 1day 20 .setCookie('user_session', '75442486-0878-440c-9db1-a7006c25a39f', { 21 expire: 'Sat, 13 Mar 2017 12:25:57 GMT', 22 })
1this.$cookie.setCookie('default_unit_second', 'input_value', { expire: 1 }) // 1 second after, expire 2this.$cookie.setCookie('default_unit_second', 'input_value', { 3 expire: 60 + 30, 4}) // 1 minute 30 second after, expire 5this.$cookie.setCookie('default_unit_second', 'input_value', { 6 expire: 60 * 60 * 12, 7}) // 12 hour after, expire 8this.$cookie.setCookie('default_unit_second', 'input_value', { 9 expire: 60 * 60 * 24 * 30, 10}) // 1 month after, expire
1this.$cookie.setCookie('default_unit_second', 'input_value', { expire: 0 }) // end of session - use 0 or "0"!
Unit | full name |
---|---|
y | year |
m | month |
d | day |
h | hour |
min | minute |
s | second |
Unit Names Ignore Case
not support the combination
not support the double value
1this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 2 expire: '60s', 3}) // 60 second after, expire 4this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 5 expire: '30MIN', 6}) // 30 minute after, expire, ignore case 7this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 8 expire: '24d', 9}) // 24 day after, expire 10this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 11 expire: '4m', 12}) // 4 month after, expire 13this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 14 expire: '16h', 15}) // 16 hour after, expire 16this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 17 expire: '3y', 18}) // 3 year after, expire 19 20// input date string 21this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 22 expire: new Date(2017, 3, 13).toUTCString(), 23}) 24this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 25 expire: 'Sat, 13 Mar 2017 12:25:57 GMT ', 26})
1var date = new Date() 2date.setDate(date.getDate() + 1) 3this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 4 expire: date, 5})
1this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { 2 expire: Infinity, 3}) // never expire 4// never expire , only -1,Other negative Numbers are invalid 5this.$cookie.setCookie('token', 'GH1.1.1689020474.1484362313', { expire: -1 })
1this.$cookie.setCookie('token', 'value') // domain.com and *.doamin.com are readable 2this.$cookie.removeCookie('token') // remove token of domain.com and *.doamin.com 3 4this.$cookie.setCookie('token', value, { domain: 'domain.com' }) // only domain.com are readable 5this.$cookie.removeCookie('token', { domain: 'domain.com' }) // remove token of domain.com
1// set path 2this.$cookie.setCookie('use_path_argument', 'value', { 3 expire: '1d', 4 path: '/app', 5}) 6 7// set domain 8this.$cookie.setCookie('use_path_argument', 'value', { domain: 'domain.com' }) // default 1 day after,expire 9 10// set secure 11this.$cookie.setCookie('use_path_argument', 'value', { 12 secure: true, 13}) 14 15// set sameSite - should be one of `None`, `Strict` or `Lax`. Read more https://web.dev/samesite-cookies-explained/ 16this.$cookie.setCookie('use_path_argument', 'value', { sameSite: 'Lax' })
1// check a cookie exist 2this.$cookie.isCookieAvailable("user_session") 3 4// get a cookie 5this.$cookie.getCookie("user_session"); 6 7// remove a cookie 8this.$cookie.removeCookie("user_session"); 9 10// get all cookie key names, line shows 11this.$cookie.keys().join("\n"); 12 13// remove all cookie 14this.$cookie.keys().forEach(cookie => this.$cookie.removeCookie(cookie)) 15 16// vue-cookie-next global 17[this | VueCookieNext].$cookie.[method] 18
$cookie key names Cannot be set to ['expires','max-age','path','domain','secure','SameSite']
This project is heavily inspired by the following awesome projects.
Thanks!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
security policy file not detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
72 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More