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

zjjk-lishizhen

v3.0.7

Published

咱家健康前端代码库-李时珍

Downloads

147

Readme

安装

npm install zjjk-lishizhen --save

使用方法

// 全量引入
import lishizhen from 'zjjk-lishizhen'
// 根据身份证号,获取生日、年龄、性别
lishizhen.common.idCardNo('130106199901181811')
// 向本地localStorage存储变量name 值为张三
lishizhen.data.setData('name', '张三')

// 部分引入
import { common, data } from 'zjjk-lishizhen'
// 根据身份证号,获取生日、年龄、性别
common.idCardNo('130106199901181811')
// 向本地localStorage存储变量name 值为张三
data.setData('name', '张三')

类别

  • common 公共方法
  • time 时间相关方法
  • data 本地存储相关方法
  • cookie cookie相关方法
  • mobile 移动端相关代码
  • validate 公共验证规则
  • dessert 常用的小功能(甜点)

common 公共方法

jsGetAge 根据生日判断年龄,返回周岁

/**
 * 根据生日判断年龄,返回周岁
 * @param {String} 生日 1986-01-18
 * @return {Number}
 */
lishizhen.common.jsGetAge('1986-01-18') // 37

idCardNo 根据身份证号,获取生日、年龄、性别

/**
 * 根据身份证号,获取生日、性别、年龄、地址码
 * @param {String} 身份证号
 * @return {Boolean|Object}
 *   Boolean: 返回false表示身份证不正确
 *   Object: {birthday: 生日, birthday: 生日, sexName: 性别, sexCode: 性别码, age: 年龄, areaCode: 地址码}
 */
lishizhen.common.idCardNo('130107197803017473')
// 返回结果
{
  birthday: "1978-03-01", // 生日
  sexName: "男", // 性别 中文
  sexCode: "1", // 性别编码 1男 2女
  age: 42, // 年龄
  areaCode: "130107" // 地址码
}

getAbsoluteLocation 获取指定元素距离屏幕的距离

<div id="demo" style="position: absolute; top: 100px; left: 100px; background-color: red; width:150px; height: 150px;"></div>
/**
 * 获取指定元素距离屏幕的距离
 * @param {DOM} element
 * @return {Boolean|Object}
 *   Boolean: 返回false表示DOM元素不正确
 *   Object: {top: 距离顶部距离, left: 距离左侧距离, offsetWidth: 元素宽度, offsetHeight: 元素高度}
 */

lishizhen.common.getAbsoluteLocation(document.getElementById('demo'))
// 返回的数据
{
  top: 100, // 距离顶部距离
  left: 100, // 距离左侧距离
  offsetWidth: 150, // 元素宽度
  offsetHeight: 150 // 元素高度
}

getUrlParameter 获取当前url中的protocol、host、port、query等参数

/**
 * 获取当前url中的protocol、host、port、query等参数
 * @param {String} url 需要解析的url
 * @return {Array} 返回数组包含当前url各项参数
 */

getQueryString 获取查询字符串的值

/**
 * 获取当前url中参数的值
 * @param {String} 要查询的key名
 * @return {String}
 */
lishizhen.common.getQueryString('name')

银行卡号4位分割

/**
 * 银行卡号4位分割
 * @param {String} 要分隔的银行卡号
 * @param {String} 分隔符 默认 ' '
 * @return {String}
 */
lishizhen.common.splitBy4Bit('6228480632103493455') // '6228 4806 3210 3493 455'
lishizhen.common.splitBy4Bit('6228480632103493455', '-') // '6228-4806-3210-3493-455'

手机号3-4-4分割

/**
 * 手机号3-4-4分割
 * @param {String} 要分隔的手机号
 * @param {String} 分隔符 默认 ' '
 * @return {String}
 */
lishizhen.common.splitBy3Bit('15133124118') // '151 3312 4118'
lishizhen.common.splitBy3Bit('15133124118', '-') // '151-3312-4118'

queryStringToObject 查询字符串转对象

/**
 * 查询字符串转对象
 * @param {String} 要转换的查询字符串
 * @return {Object} 转换后的对象
 */
lishizhen.common.queryStringToObject('name=张三&age=20') // {name: "张三", age: "20"}

objectToQueryString 对象转查询字符串

/**
 * 对象转查询字符串
 * @param {Object} 要转换的对象
 * @return {String} 转换后的查询字符串,会对值做 encodeURIComponent 处理
 */
lishizhen.common.objectToQueryString({name: "张三", age: "20"}) // 'name=%E5%BC%A0%E4%B8%89&age=20' 会对值做 encodeURIComponent 处理

读取深层属性

/**
 * 读取深层属性,如果读取不存在的属性则返回默认值 默认undefined
 * @param {Object} obj 要读取的对象
 * @param {String} attrPath 多层属性表示形式: a|a.b|a.b.c 等无限级深度
 * @param {Any} defaultVal 没有读取到属性时的默认值 默认undefined
 * @param {String} separator 深层属性的分隔符 默认'.'
 * @returns {Any} 读取的值
 */
let obj = {
  data: {
    a: 123
  }
}
lishizhen.common.getDeepValue(obj, 'data.a') // 123
lishizhen.common.getDeepValue(obj, 'data.b') // undefined
lishizhen.common.getDeepValue(obj, 'data.b', null) // 设置默认返回值 null

设置深层属性

/**
 * 设置深层属性
 * @param {Object} obj 要赋值的对象
 * @param {String} attrPath 多层属性表示形式: a.b.c
 * @param {any} value 要设置的值
 */
let obj = {
  data: {
    a: 123
  }
}
lishizhen.common.setDeepValue(obj, 'data.a', 456)
console.log(obj) // {data: {a: 456}}

dateFtt 格式化时间函数

/**
 * 格式化时间函数
 * @param {String} 格式化日期的格式字符串 yyyy-MM-dd hh:mm:ss:S q
 * @param {String|Date} '2017-01-11 12:12:55' 时间字符串 | '2017/01/11 12:12:55' 时间字符串 | 时间戳 秒、毫秒 | new Data() 时间对象
 * @return {String} 2017-12-09 12:22:03:233 4
 */
lishizhen.common.dateFtt('yyyy-MM-dd', new Date()) // 使用时间对象格式化 2021-03-19
lishizhen.common.dateFtt('yyyy-MM-dd hh:mm:ss', '2017-01-11 12:12:55') // 使用时间字符串格式化 2017-01-11 12:12:55
lishizhen.common.dateFtt('yyyy-MM-dd hh:mm:ss', '2017/01/11 12:12:55') // 使用时间字符串格式化 2017-01-11 12:12:55
lishizhen.common.dateFtt('yyyy-MM-dd hh:mm:ss', '1620616873108') // 使用时间戳格式化 2021-03-19 11:14:22

isForbid 检查是否含有非法字符

/**
 * 检查是否含有非法字符
 * 非法字符包括:?、?、!、!、*、--、/、+、\、\\、$、^、.、;、<、>、=、{、}、%、~、&
 * @param {String} 要检测的字符串
 * @return {Boolean}
 */
lishizhen.common.isForbid('fdaf!xx') // true
lishizhen.common.isForbid('abcdefg') // false

isIE 检测是否是IE浏览器

/**
 * 检测是否是IE浏览器
 * @return {Boolean}
 */
lishizhen.common.isIE() // 返回 true 或 false

deepCopy 深度拷贝对象

/**
 * 深度拷贝对象
 * @param {Object} 要进行深度拷贝的对象
 * @return {Object} 拷贝后的新对象
 */
var a = {
  name: '张三',
  age: 22,
  say() {
    console.log('函数也可以拷贝哦')
  }
}
var d = lishizhen.common.deepCopy(a)
a === d // false
var e = a
e === a // true

deepMerge 深度合并对象

/**
 * 深度合并对象
 * @param {Objec} 要进行深度合并的对象1
 * @param {Objec} 要进行深度合并的对象2
 * @return {Objec} 深度合并后的新对象
 */
lishizhen.common.deepMerge({name: '张三'}, {age: 20}) // {name: '张三', age: 20}

secToTime 秒数转时间字符串

/**
 * 秒数转时间字符串
 * @param {Number} 秒数 如:86400
 * @return {String} 格式化后的时分秒,如:'24:00:00'
 */
lishizhen.common.secToTime(3600) // '01:00:00'

timeToSec 时间字符串转为秒

/**
 * 时间字符串转为秒
 * @param {String} 时间字符串 '24:00:00'
 * @return {Number} 秒数 如:86400
 */
// 1小时
lishizhen.common.timeToSec('01:00:00') // 3600
// 24小时
lishizhen.common.timeToSec('24:00:00') // 86400

格式化数字,比如数字千分位

/**
 * 格式化数字,比如数字千分位
 * @param {String|Number} 要格式化的数字
 * @param {Number} 每隔几位数进行分割 默认3
 * @param {Number} 要保留的小数位 默认2
 * @param {String} 用来分割的符号,默认,
 * @return {String} 1,234,567.00
 */
lishizhen.common.formatNumber('11111') // '11,111.00'
lishizhen.common.formatNumber('11111', 2) // '1,11,11.00'
lishizhen.common.formatNumber('11111', 2, 0) // '1,11,11'
lishizhen.common.formatNumber('11111', 2, 0, '|') // '1|11|11'

compressImage 压缩图片 默认会自动校正图片角度

/**
 * 压缩图片
 * @param {File} 图片文件元素 <input type="file"/>元素 event.target.files[0]
 * @param {Number} 图片最大宽度 0或负数表示不限制宽度 默认800(单位px)
 * @param {String | Number} 图片输出类型 默认jpg;可选png
 * @param {Float} 图片质量 只有outputType为jpg时有效 默认0.9
 * @param {Boolean} 是否校正图片角度 默认true
 * @return {Promise} original: 原图片的base64值; thumb: 处理后图片的base64值
 */
lishizhen.common.compressImage(file).then(res => {
  console.log('原图base64值:' + res.original)
  console.log('压缩图base64值:' + res.thumb)
})

// 设置最大宽度为1200,设置压缩图质量为1(100%)
lishizhen.common.compressImage(file, 1200, 'jpg', 1).then(res => {
  console.log('原图base64值:' + res.original)
  console.log('压缩图base64值:' + res.thumb)
})

// 设置最大宽度为1500 压缩图的格式为png
lishizhen.common.compressImage(file, 1500, 'png').then(res => {
  console.log('原图base64值:' + res.original)
  console.log('压缩图base64值:' + res.thumb)
})

rotateImage 校正图片角度

/**
 * 旋转图片
 * @param {File} 要校正的图片文件对象 <input type="file"/>元素 event.target.files[0]
 * @return {String} 校正角度后的图片的base64值
 */
lishizhen.common.rotateImage(file).then(res => {
  console.log('校正后的base64值:' + res)
})

typeOf 判断参数的数据类型

/**
 * 判断参数的数据类型
 * @param {Any} 要判断的数据
 * @return {String} boolean | number| string | function | array | date | regExp | undefined | null | object
 */
lishizhen.common.typeOf(true) // boolean
lishizhen.common.typeOf(666) // number
lishizhen.common.typeOf('56个民族是一家') // string
lishizhen.common.typeOf(function () {}) // function
lishizhen.common.typeOf([]) // array
lishizhen.common.typeOf(new Date()) // date
lishizhen.common.typeOf(/[abc]/) // regExp
lishizhen.common.typeOf() // undefined
lishizhen.common.typeOf(null) // null
lishizhen.common.typeOf({}) // object

isEmptyObj 判断参数是否是空对象

/**
 * 判断参数是否是空对象
 * @param {Object} 要判断的对象
 * @return {Boolean}
 */
lishizhen.common.isEmptyObj({name: '张三'}) // false
lishizhen.common.isEmptyObj({}) // true

isWechat 判断是否是微信端

/**
 * 判断是否是微信端
 * @return {Boolean}
 */
lishizhen.common.isWechat() // 返回 true 或 false

isMobile 判断是否是移动端

/**
 * 判断是否是移动端
 * @return {Boolean}
 */
lishizhen.common.isMobile() // 返回 true 或 false

isPc 判断是否是PC端

/**
 * 判断是否是PC端
 * @return {Boolean}
 */
lishizhen.common.isPc() // 返回 true 或 false

print 打印指定区域内容

/**
 * 打印指定区域内容
 * @param {DOM} 要打印的区域元素
 */
lishizhen.common.print(document.getElementById('div'))

getScrollWidth 获取浏览器滚动条的宽度

/**
 * 获取浏览器滚动条的宽度
 * @return {Number}
 */
lishizhen.common.getScrollWidth() // 17

desensitizationIdCard 身份证号脱敏

/**
 * 判断是否是PC端
 * @param {String} 要脱敏的身份证号
 * @return {String} 脱敏后的身份证号
 */
lishizhen.common.desensitizationIdCard('130105198601181814') // 13010519860118****

desensitizationPhone 手机号脱敏

/**
 * 手机号脱敏
 * @param {String} 要脱敏的手机号
 * @return {String} 脱敏后的手机号
 */
lishizhen.common.desensitizationPhone('15133124555') // 151****4555

debounce 创建防抖函数

/**
 * 创建防抖函数
 * @param {Function} 处理函数
 * @param {Number} 防抖的延时 单位毫秒
 * @return {Function}
 */
let debounce = lishizhen.common.debounce(() => {
  console.log('hello world!')
}, 300)
debounce()

throttle 创建节流函数

/**
 * 创建节流函数
 * @param {Function} 处理函数
 * @param {Number} 节流的延时 单位毫秒
 * @return {Function}
 */
let throttle = lishizhen.common.throttle(() => {
  console.log('hello world!')
}, 300)
throttle()

requestAnimFrame 动画函数(requestAnimationFrame兼容写法)

time 时间相关方法

getMonthDays 获得本年某月的天数

/**
 * 获得本年某月的天数
 * @params myMonth 要获取天数的月份
 */
lishizhen.time.getMonthDays(1) // 31
lishizhen.time.getMonthDays(4) // 30

getQuarterStartMonth 获得本季度的开端月份

/**
 * 获得本季度的开端月份
 * 返回结果 加1,不是返回的下标。内部调用时需注意
 */
lishizhen.time.getQuarterStartMonth() // 4

getWeekStartDate 获得本周开始日期。注意 星期日是第一天

/**
 * 获得本周开始日期
 * 星期日是第一天
 * @return {String}
 */
lishizhen.time.getWeekStartDate() // '2021-05-09'

getWeekEndDate 获得本周结束日期。注意 星期六是最后一天

/**
 * 获得本周结束日期
 * 星期六是最后一天
 * @return {String}
 */
lishizhen.time.getWeekEndDate() // '2021-05-15'

getMonthStartDate 获得本月开始日期

/**
 * 获得本月开始日期
 * @return {String}
 */
lishizhen.time.getMonthStartDate() // '2021-05-01'

getMonthEndDate 获得本月结束日期

/**
 * 获得本月结束日期
 * @return {String}
 */
lishizhen.time.getMonthEndDate() // '2021-05-31'

getLastMonthStartDate 获得上月开始日期

/**
 * 获得上月开始日期
 * @return {String}
 */
lishizhen.time.getLastMonthStartDate() // '2021-04-01'

getLastMonthEndDate 获得上月结束日期

/**
 * 获得上月结束日期
 * @return {String}
 */
lishizhen.time.getLastMonthEndDate() // '2021-04-30'

getQuarterStartDate 获得本季度的开端日期

/**
 * 获得本季度的开端日期
 * @return {String}
 */
lishizhen.time.getQuarterStartDate() // '2021-04-01'

getQuarterEndDate 获得本季度的停止日期

/**
 * 获得本季度的停止日期
 * @return {String}
 */
lishizhen.time.getQuarterEndDate() // '2021-06-30'

getDate 获取几天前或几天后的日期对象、或格式化后的日期字符串

/**
 * 获取几天前或几天后的日期对象、或格式化后的日期字符串
 * @param {Number} 获取第几天前 默认0获取当天 >0获取几天后的日期 <0获取几天前的日期
 * @param {String|null} 格式化日期的格式字符串 yyyy-MM-dd hh:mm:ss;传null时返回时间类型
 * @param {Date|String} 指定的时间,默认为当前时间
 * @return {Date|String}
 */
lishizhen.time.getDate() // 获取当天 字符串类型 的值 '2021-05-10 15:54:39'
lishizhen.time.getDate(-1) // 获取昨天 字符串类型 的值 '2021-05-10 15:54:39'
lishizhen.time.getDate(-1, null) // 获取昨天 时间对象类型 的值 Sun May 09 2021 15:55:37 GMT+0800 (中国标准时间)
lishizhen.time.getDate(-1, 'yyyy-MM-dd hh:mm:ss', '2020-12-12 11:11:22') // 返回2020-12-12 11:11:22的前一天 字符串类型 的值 2020-12-11 11:11:22

getDayOfWeek 获取今天是周几

/**
 * 获取今天是周几
 * @param {Date} date
 * @return {String}
 */
lishizhen.time.getDayOfWeek(new Date())

todayStartTime 获取当天开始时间 2021-11-11 00:00:00

/**
 * 获取当天开始时间
 * @param {String|null} fmt 格式化日期的格式字符串 yyyy-MM-dd hh:mm:ss;传null时返回时间类型
 * @returns {String|Date}
 */
lishizhen.time.todayStartTime() // 2021-05-10 11:11:52
lishizhen.time.todayStartTime('yyyy-MM-dd') // 2021-05-10
lishizhen.time.todayStartTime(null) // Mon May 10 2021 00:00:00 GMT+0800 (中国标准时间)

todayEndTime 获取当天结束时间 2021-11-11 23:59:59

/**
 * 获取当天结束时间
 * @param {String|null} fmt 格式化日期的格式字符串 yyyy-MM-dd hh:mm:ss;传null时返回时间类型
 * @returns {String|Date}
 */
lishizhen.time.todayEndTime() // 2021-05-10 23:59:59
lishizhen.time.todayEndTime('yyyy-MM-dd') // 2021-05-10
lishizhen.time.todayEndTime(null) // Mon May 10 2021 23:59:59 GMT+0800 (中国标准时间)

data 本地存储相关方法

setData 设置本地存储 localStorage

/**
 * 设置本地存储 localStorage
 * @param {String} 要存储的key
 * @param {String|Object|Array} 要存储的value
 */
lishizhen.data.setData('name', '张三') // 存储字符串
lishizhen.data.setData('name', {name: '张三', age: 22}) // 存储对象
lishizhen.data.setData('name', ['张三', '李四']) // 存储数组

getData 获取指定key值数据 localStorage

/**
 * 获取指定key值数据 localStorage
 * @param {String} 要获取数据的key
 * @param {Any} 当获取的数据为空时,返回的默认数据
 */
lishizhen.data.getData('name') // 如果有值则返回存储的值,如果没有则返回 undefined
lishizhen.data.getData('name', '李四') // 如果有值则返回存储的值,如果没有则返回 李四

setSessionData 设置本地存储 sessionStorage

/**
 * 设置本地存储 sessionStorage
 * @param {String} 要存储的key
 * @param {String|Object|Array} 要存储的value
 */
lishizhen.data.setSessionData('name', '张三') // 存储字符串
lishizhen.data.setSessionData('name', {name: '张三', age: 22}) // 存储对象
lishizhen.data.setSessionData('name', ['张三', '李四']) // 存储数组

getSessionData 获取指定key值数据 sessionStorage

/**
 * 获取指定key值数据 sessionStorage
 * @param {String} key 要获取数据的key
 * @param {Any} def 当获取的数据为空时,返回的默认数据
 */
lishizhen.data.getSessionData('name') // 如果有值则返回存储的值,如果没有则返回 undefined
lishizhen.data.getSessionData('name', '李四') // 如果有值则返回存储的值,如果没有则返回 李四

setCache 缓存数据 localStorage

/**
 * 缓存数据 localStorage
 * @param {String} key 要存储的key
 * @param {String|Object|Array} value 要存储的value
 * @param {String|Number} time 数据的有效时间,单位秒
 */
lishizhen.data.setSessionData('name', '张三', 60) // 存储1分钟
lishizhen.data.setSessionData('name', {name: '张三', age: 22}, 60) // 存储1分钟
lishizhen.data.setSessionData('name', ['张三', '李四'], 60) // 存储1分钟

getCache 获取缓存数据 localStorage

/**
 * 获取缓存数据 localStorage
 * @param {String} key 要获取数据的key
 * @param {Any} def 当获取的数据为空时,返回的默认数据
 */
lishizhen.data.getCache('name') // 如果有值则返回存储的值,如果没有则返回 undefined
lishizhen.data.getCache('name', '李四') // 如果有值则返回存储的值,如果没有则返回 李四

cookie cookie相关方法

setCookie 添加cookie(别名addCookie)

/**
 * 添加cookie
 * objHours设置cookie存储时间,默认 0;表示浏览器关闭时cookie自动消失
 * @param {String} cookie名称
 * @param {String} 要存储的值
 * @param {Number} 要存储的时间 单位小时
 */
lishizhen.cookie.addCookie('name', '张三') // 浏览器关闭时cookie自动消失,这种cookie被叫做会话cookie
lishizhen.cookie.addCookie('name', '张三', 1) // 存储1小时

getCookie 获取cookie

/**
 * 获取cookie
 * @param {String} cookie名称
 * @return {String} key对应的值
 */
lishizhen.cookie.getCookie('name') // '张三'

delCookie 删除cookie

/**
 * 删除cookie
 * @param {String} objName
 */
lishizhen.cookie.delCookie('name')

mobile 移动端相关代码

rem 计算页面rem

/**
 * 计算页面rem
 * @param {Number} 设计稿宽度 默认750
 * @param {Function} 设置完根元素字号后的回调函数
 * @param {Boolean} 回调函数是否只执行一次 默认false
 */
// 默认设计稿宽为750px
lishizhen.mobile.rem(() => {
  console.log('页面尺寸发生了改变')
})

// 设计稿宽为1080px
lishizhen.mobile.rem(1080, () => {
  console.log('页面尺寸发生了改变')
})

// 设计稿宽为1080px 回调函数只执行一次
lishizhen.mobile.rem(1080, () => {
  console.log('页面尺寸发生了改变')
}, true)

wechatReload 刷新微信H5页面

/**
 * 解决微信端无法使用window.location.reload()刷新页面的方法
 */
lishizhen.mobile.wechatReload()

forceReLoad

/**
 * 解决微信IOS端H5页面返回后,页面不刷新的问题
 * 参考:https://segmentfault.com/a/1190000018768189
 */

os 返回手机系统

/**
 * 返回手机系统
 * @return {String}
 */
lishizhen.mobile.os() // 返回 android 或 ios

iosVersion 获取IOS版本号

/**
 * 获取IOS版本号
 * @return {Number} IOS版本号
 */
lishizhen.mobile.iosVersion() // 14.5

keyboardIsOpen(callback) 判断软键盘是否弹出

/**
 * 判断软件盘是否弹出
 * @param {Function} 弹出或关闭软键盘后的回调
 * @param {Boolean} 键盘收起后,是否恢复页面位置 默认false
 * @param {String} 要监听的系统 也可以设置 'android' 或 'ios' 默认 'all'全部监听
 * @return {Function} 返回注销函数句柄 一般在vue组件的销毁生命周期中调用
 */
let destroy = lishizhen.mobile.keyboardIsOpen(isOpen => { // 返回注销函数句柄 destroy
  console.log('键盘是否打开:' + isOpent) // true 或 false
})
destroy() // 注销监听

// 键盘收起后,恢复页面位置。在出现位置不正确的时候可以使用此参数
let destroy = lishizhen.mobile.keyboardIsOpen(isOpen => {
  console.log('键盘是否打开:' + isOpent) // true 或 false
}, true)

callNativeFunction 调原生的方法

/**
 * 调原生的方法
 * @param {String} 要调用的方法名
 * @param {Object} 要传递的参数
 */
lishizhen.mobile.callNativeFunction()

closeWindow 关闭当前窗口

/**
 * 关闭当前窗口
 * 兼容客户端的closeSelf 和 微信的wx.closeWindow
 */
lishizhen.mobile.closeWindow()

validate 公共验证规则

idCard 验证身份证号是否合法

/**
 * 验证身份证号是否合法
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.idCard('130106198601181811') // true
lishizhen.validate.idCard('123456789') // false

phone 验证手机号是否合法

/**
 * 验证手机号是否合法
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.phone('1513324118') // true
lishizhen.validate.phone('1111112222') // false

chinese 验证指定的内容是否都是中文

/**
 * 验证指定的内容是否都是中文
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.chinese('中国') // true
lishizhen.validate.chinese('abc') // false

postalCode 验证邮政编码是否合法

/**
 * 验证邮政编码是否合法
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.postalCode('050061') // true
lishizhen.validate.postalCode('999999') // false

email 验证指定的内容是否是email地址

/**
 * 验证指定的内容是否是email地址
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.email('[email protected]') // true
lishizhen.validate.email('abcdefg') // false

url 验证指定的内容是否是URL地址 - 地址必须以http/https/ftp/ftps开头

/**
 * 验证指定的内容是否是URL地址
 * 地址必须以http/https/ftp/ftps开头
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.email('http://www.baidu.com') // true
lishizhen.validate.email('https://www.baidu.com') // true
lishizhen.validate.email('ftp://www.baidu.com') // true
lishizhen.validate.email('ftps://www.baidu.com') // true
lishizhen.validate.email('abcdefg') // false

ip 验证指定的内容是否是IP

/**
 * 验证指定的内容是否是IP
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.ip('192.168.11.1') // true
lishizhen.validate.ip('192554112') // false

emoji 验证指定的内容是否包含emoji表情符

/**
 * 验证指定的内容是否包含emoji表情符
 * @param {String}
 * @return {Boolean}
 */
lishizhen.validate.emoji('Meanings 💁👌🎍😍') // true
lishizhen.validate.emoji('abcdefg') // false
lishizhen.validate.emoji('中国') // false

dessert 常用的小功能

goTop 平滑的返回到页面顶端

/**
 * 平滑的返回到页面顶端
 */
lishizhen.dessert.goTop()