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

saber-cookie

v2.0.0-alpha.2

Published

适合移动端的Cookie封装。

Downloads

1

Readme

saber-cookie Build Status

适合移动端的Cookie封装

Installation

通过 edp 引入模块:

edp import saber-cookie

Usage

require('saber-cookie', function(Cookie) {
    // create a cookie (page-session)
    Cookie.set('__saber_test', 'saber');
    
    // get a cookie with given name
    var val = Cookie.get('__saber_test');
    console.info(val);
    
    // create a cookie with expires (1 day)
    Cookie.set(
        '__saber_1d',
        '1day',
        {expires: 1 * 24 * 60 * 60 * 1000}
    );
    console.info(Cookie.get('__saber_1d'));
    
    // create a cookie with path
    Cookie.set(
        '__saber_root',
        'root',
        {path: '/'}
    );
    console.info(Cookie.get('__saber_root'));
    
    // create a cookie with domain
    Cookie.set(
        '__saber_host',
        {domain: document.domain}
    );
    console.info(Cookie.get('__saber_host'));
    
    // create a cookie with raw value
    Cookie.set(
        '__saber_raw',
        'hello, saber',
        {raw: true}
    );
    console.info(
        'decoded: %s , raw: %s',
        Cookie.get('__saber_raw'),
        Cookie.get('__saber_raw', {raw: true})
    );
    
    // remove a cookie
    Cookie.set('__saber_remove', 'xx');
    var beforeVal = Cookie.get('__saber_remove');
    Cookie.remove('__saber_remove');
    var afterVal = Cookie.get('__saber_remove');
    console.info('before: %s , after: %s', beforeVal, afterVal);
});

Methods

get(name [, options])

获取键名为 name 的 cookie 值,若 cookie 不存在或 name 为空,则返回 null

  • name {string} cookie的键名
  • options {Object} 参数可选,支持的配置项:
    • raw {boolean} 是否不自动解码(decodeURIComponent), 为true时会获取未经过解码的cookie原始存储值
  • return {string}
// 获取键名为 mycookie 的 cookie 值
Cookie.get('mycookie');

// 获取键名为 rawcookie 的未解码的 cookie 存储值
Cookie.get('rawcookie', {raw: true});

set(name, value[, options])

设置键名为 name,值为 value 的新 cookie

  • name {string} cookie的键名
  • value {string} cookie的原始值
  • options {Object} 参数可选,支持的配置项:
    • expires {Date|Number} cookie的过期时间, 为数字时单位为毫秒
    • domain {string} cookie的域名
    • path {string} cookie路径
    • secure {boolean} cookie是否安全传输
    • raw {boolean} 是否不自动编码(encodeURIComponent), 为true时参数value会以未编码的原始值存储
  • return {void}
// 默认(session级)的新cookie
Cookie.set('test1', 'session cookie');

// 设置了有1天效期的新cookie
Cookie.set('test2', 'baidu', {
    expires: 1 * 24 * 60 * 60 * 1000
});

// 设置了路径的新cookie
Cookie.set('test3', 'baidu', {path: '/'});

// 设置了域名的新cookie
Cookie.set('test4', 'baidu', {domain: 'baidu.com'});

// 设置了安全传输的新cookie
Cookie.set('test5', 'baidu', {secure: true});

// 禁用自动编码(encodeURIComponent)的cookie
Cookie.set('test6', 'hello, saber', {raw: true});

remove(name[, options])

删除键名为 name 的 cookie

  • name {string} cookie的键名
  • options {Object} 参数可选,支持的配置项:
    • domain {string} cookie的域名
    • path {string} cookie路径
    • secure {boolean} cookie是否安全传输
  • return {void}
// 删除键名为 mycookie 的 cookie
Cookie.remove('mycookie');

// 删除 `baidu.com` 域下,路径为 `/` 的键名为 `othercookie` 的 cookie
Cookie.remove('othercookie', {domain: 'baidu.com', path: '/'});