npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cookie-web

v1.1.0

Published

Encapsulated cookie module,make cookies simpler.

Downloads

8

Readme

cookie-web

NPM Version NPM Version NPM Version

Make cookies simpler.

Install

npm install cookie-web
yarn add cookie-web

Methods

const cookie = require('cookie-web')
import cookie from 'cookie-web'

void cookie.setOne (key, val, options = {})

Set a cookie based on a key-value pair.
Of course, there are also other configuration items

options = {  
    expires,  // Expires time
    path,  // Accessible path
    domain,  // Accessible hostname
    secure  // Encrypted Transport (true / false)
}

so, how to use it?

cookie.setOne('myCookie', 'test')
cookie.setOne(2, 'test') // TypeError: key must be a string !
cookie.setOne('test') // TypeError: key can't be undefined !
cookie.setOne('myCookie', 2) // TypeError: val must be a string !
cookie.setOne('myCookie') // TypeError: val can't be undefined !
cookie.setOne('myCookie', 'test', {
    expires: 1 * 1000 * 60, // one minite
})
cookie.setOne('myCookie', 'test', {
    expires: 1 * 1000 * 60 * 60, // one hour
    path: '/', // also: /someRoute
    domain: '.google.com',
    secure: true
})

void cookie.set(obj)

Create multiple cookies from an array of objects or objects.
[{key, val, options}] or {key, val, options}

cookie.set([{
      key: 'cookie_1',
      val: 'value_1'
    },
    {
      key: 'cookie_2',
      val: 'value_2',
      options: {
        path: '/home'
      }
    },
    {
      key: 'cookie_3',
      val: 'value_3',
      options: {
        path: '/home',
        expires: 1 * 1000 * 60 * 60,
        secure: true
      }
    },
    {
      key: 'cookie_4',
      val:'value_4',
      options: {
        path: '/menu',
        expires: 1 * 1000 * 60 * 60
      }
    }])
    
cookie.set({
      key: 'cookie_1',
      val: 'value_1'
    })

string cookie.getOne(key)

Get a cookie by key name
use it !

cookie.setOne('myCookie_1', 'hello')
cookie.setOne('myCookie_2', 'my-cookie')

cookie.getOne('myCookie_1') // 'hello'
cookie.getOne('myCookie_1', true) // {'myCookie_1': 'hello'}
cookie.getOne('myOtherCookie') // undefined
cookie.getOne(true) // { myCookie_1: 'hello', myCookie_2: 'my-cookie' }
cookie.getOne() // ['hello', 'my-cookie']

cookie.get(keys)

Get multiple cookies from a string array or string and choose how to return the result

cookie.set([{
      key: 'cookie_1',
      val: 'value_1'
    },
    {
      key: 'cookie_2',
      val: 'value_2',
    }])

cookie.get(['cookie_1', 'cookie_2'], true) // [{'cookie_1': 'value_1'}, {'cookie_2': 'value_2'}]
cookie.get() // ['value_1', 'value_2']
cookie.get('cookie_1', true) // {'cookie_1', 'value_1'}
cookie.get('cookie_1') // 'value_1'

void cookie.deleteOne(key, options)

Delete a cookie by key name
Of course, when you set the path/domain property before you create it you should set options,it must be the same as you create it!

options = {
    path,
    domain
}

use it !

cookie.setOne('myCookie_1', 'hello')
cookie.setOne('myCookie_2', 'my-cookie')
cookie.getOne() // ['hello', 'my-cookie']
cookie.deleteOne('myCookie_1')
cookie.getOne() // ['my-cookie']
cookie.deleteOne()
cookie.getOne() // undefined

But when you set the path/domain property before you create it, when deleting, you must use the same path and domain to delete it correctly!

cookie.setOne('myCookie_1', 'hello', {
    path: '/home',
    domain: '.google.com'
})
cookie.deleteOne('myCookie_1', {
    path: '/home',
    domain: '.google.com'
}) // delete 'myCookie_1'
cookie.deleteOne(undefined, {
    path: '/home',
    domain: '.google.com'
}) // delete all path: '/home' , domain: '.google.com'

void cookie.delete(keys)

Delete multiple cookies from a string array or string

cookie.set([{
      key: 'cookie_1',
      val: 'value_1'
    },
    {
      key: 'cookie_2',
      val: 'value_2'
    },
    {
      key: 'cookie_3',
      val: 'value_3',
      options: {
        path: '/home'
      }
    },
    {
      key: 'cookie_4',
      val:'value_4'
    }])


cookie.delete([
    'cookie_1',
    'cookie_2',
    {
      key: 'cookie_3',
      options: {
        path: '/home'
      }
    }])
cookie.delete('cookie_4')
cookie.delete() // delete all path: '/'

Thanks !