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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jason-user

v0.1.0

Published

> 一个简单的用户登录状态管理

Readme

jason-user

一个简单的用户登录状态管理

安装

npm i --save jason-user

API

import User from 'jason-user';

实例化用户

实例化时 将根据 storage 中的数据自动更新一次 this.data 实现记住密码功能

let user = new User({
  // 可选
  // 用户数据存入 sessionStore 或 localStore 中的 key 值
  storageKey: 'jason-user',
  
  // 登录逻辑核心函数
  // 必有
  // 这个函数通常返回 Promise,也可以同步返回结果
  // resolve 或 同步返回值应该是一个对象(或无返回值代表登陆失败)
  // 包含着用户状态数据
  login (params) {
    return data
  },
  
  // 验证用户身份是否有效的核心代码
  // 可选
  // 这个函数通常返回 Promise,也可以同步返回结果
  // 若无,则调用 user.verify 时会返回 false
  // 这个函数应该返回结果 true 和 false
  verify () {
    return false;
  },
  
  // 当用户数据改变时(update)
  // 传入用户状态数据
  onUpdate
})

登录

这个方法将返回一个 Promise 核心实现是基于实例化时传入的 login 函数 resolve 时会有 result 参数(Boolean) 代表登录成功还是失败

user.login()
  .then(result => console.log(result))
// => true / false

获取用户属性

user.data 一定是一个对象或者为 null

console.log(user.data)

更新用户数据

传入的参数会以 assign 的方式进行新旧值对象合并到 this.data 注意:update 方法的参数必须是一个对象或者 null

user.update({ name: 'xxx', age: 18 })

检测用户登录状态是否有效

这个方法将返回一个 Promise 核心实现是基于实例化时传入的 verify 函数 resolve 时会有 result 参数(Boolean) 代表验证成功还是失败

user.verify()
  .then(result => console.log(result))
// => true / false

记录登录状态

默认会以 sessionStorage 的方式记住 传入 true 则以 localStorage 的方式记住

user.remember();
// user.remember(true);

退出登录

将会清空 user.data

user.logout();