Giter Club home page Giter Club logo

util-es's Introduction

util-es

JavaScript常用方法

非常抱歉, 因操作失误导致npm上v0.1.10以前版本全都没了, 之后的版本完全兼容以前的写法, 请放心食用 orz

使用方法

通过npm安装

npm i util-es
import Util from 'util-es'
import { isEmpty, Session } from 'util-es'

const Util = request('util-es')

通过<script>标签引用

util.min.js

此方法是向window对象中注册一个 util 对象

规则

  • 驼峰命名的为方法
  • 首写字母大写为对象

对象

对象名 描述
Session 对sessionStorage的封装
Local 对localStorage的封装
Cookie 对document.cookie的封装
Session & Local
  • 可以直接存储{}[]
  • 可以设置过期时长
方法 描述
Session.get(String key) 获取对应key的session
Session.set(String key, * value, Number second) 设置session, second(非必传 单位: 秒)
Session.remove(String key) 移除对应key的session
Session.key(Number key) 获取对应索引的键名
Session.clear() 移除所有session

Local的方法与Session一致

❗❗使用Session & Local存储对象时, 请勿使用$$ExpiryTime作为属性,这是设置过期时间的关键字

Cookie

单纯的对cookie封装, 仅支持存储字符串和设置时间

方法 header 2
get(String key) 获取对应key的Cookie
set(String key, * value, Number second) 设置Cookie, second(非必传 单位: 秒)
remove(String key) 移除对应key的Cookie

方法

方法 描述
isEmpty(* param) 判断传入数据是否为空字符或对象 ( {} [] Map Set), 返回 Boolean
isObject(* param) 判断传入数据是否为对象 ( 不包含nullundefined ), 返回 Boolean
uuid(Boolean bar) 生成并返回一个uuid ( bar:是否带 -,默认false )

其他

有问题欢迎交流, 轻喷 🙇

欢迎PR或提交issues 😃

License

This project is licensed under the MIT License

util-es's People

Contributors

lllllxt avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.