1.0.10 • Published 1 year ago

grantguo-libs v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

简介

  • 基于JavaScript, TypeScript开发的轮子库, 适用于各种Web应用开发场景·

START

  pnpm install grantguo-libs -D 或 yarn add grantguo-libs -D

  // es
  import { calendar, store } from 'grantguo-libs'
  const year = calendar.getYear()

  // cjs
  const { calendar, store } = require('grantguo-libs')
  const year = calendar.getYear()

网址链接

Calendar 使用

方法名调用方式
获取年份calendar.getYear()
获取月份calendar.getMonth()
获取日期calendar.getDate()
获取某年某月某日是星期几calendar.getWeekDay()
获取某年某月天数calendar.getDaysOfYearMonth()
获取某月第一天是星期几calendar.getWeekOfMonth()
获取完整年月日,默认以 - 拼接calendar.getFullYearMonthDay()
  /* 获取年份 */
  const year = calendar.getYear()

  /* 获取月份 */
  const month = calendar.getMonth()

  /* 获取日期 */
  const date = calendar.getDate()

  /* 获取某年某月某日是星期几, 默认输出当日 */
  const week = calendar.getWeekDay(year:number, month:number, date:number)

  /* 获取某年某月天数, 默认输出当月天数 */
  const days = calendar.getDaysOfYearMonth(year: number, month: number)

  /* 
    获取某月第一天是星期几, 默认输出当月第一天
    场景说明:
      针对每月天数及对应星期展示, 可输出个性化
  */
  const firstDay = calendar.getWeekOfMonth(year: number, month: number)

  /* 获取完整年月日, 默认以 - 拼接 */
  const yearMonthDay = calendar.getFullYearMonthDay(char:string = '-')

store 缓存的使用 (内存缓存,刷新后缓存失效)

方法名调用方式
设置store.set()
获取store.get()
检查是否有设置store.has()
删除缓存store.delete()
缓存的长度store.size()
  /* 设置缓存 键名为任意值 */
  store.set("name", 'store')

  /* 获取缓存 */
  const val = store.get("name")
 
  /* 检查是否有设置 */
  const boolean = store.has('name')  // true
 
  /* 删除缓存 */
  const boolean = store.delete('name')  // true

  /* 缓存的长度 */
  const size = store.size()

clone 的使用

方法名调用方式
深度拷贝clone.deep()
浅拷贝clone.shallow()
  const obj = {
    a: 1,
    b: 'hello',
    c: [ 1, 2, 3 ],
    d: { e: 'nested', f: [ 4, 5, 6 ] }
  }
  /* 深度拷贝 */
  const deepObj = clone.deep(obj)
  /* 深度拷贝 */
  const shallowObj = clone.shallow(obj)

test 的使用

方法名调用方式
校验手机号test.mobile()
校验邮箱test.email()
校验身份证test.idCard()
校验车牌号test.plate()
  /* 校验手机号 */
  const mobile = 17704052506
  const res = test.mobile(`${mobile}`)
  /* 校验邮箱 */
  const email = '810153274@qq.com'
  const res = test.email(email)
  /* 校验身份证 */
  const idcard = '110101199001013590'
  const res = test.idCard(idcard)
  /* 校验车牌号 */
  const plate = '京JB1295'
  const res = test.plate(plate)

idCard 的使用

方法名调用方式
获取出生年月idCard.birthday()
获取性别idCard.sex()
  /* 获取出生年月 */
  const card = '110101199001013590'
  const date = idCard.birthday(card)

  /* 获取性别 */
  const card = '110101199001013590'
  const sex = idCard.sex(card)
1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago