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

lk-tools-lib

v1.0.14

Published

前端开发工具方法集合库,整合了项目中常用的工具方法,包含了处理图片,媒体文件,常用的校验,和常用的工具方法,目的是为了在各项目中不写重复的代码

Downloads

14

Readme

lk-tools-lib

来康数智技术前端开发工具方法集合库,整合了项目中常用的工具方法

Installation

# with npm
npm install -S lk-tools-lib
# with yarn
yarn add -S lk-tools-lib

declaration

所有方法都经过测试

其中带序号的功能标题:

红色代表可以点击跳转到单元测试文件,可以更清晰地看到函数使用方法和传参形式

灰色代表没有写单元测试,但也在项目上经过测试通过,可以放心使用。

Documentation

图片

/**
 * @param {files} 文件数组对象
 * @param {ratio} 压缩参数 一般在0~1之间  
 * @returns {files} -> promise对象 使用.then可以获取压缩后的文件数组对象
 */
import { zipImage } from 'lk-tools-lib'
zipImage(files, ratio)
/**
 * @param {file} 文件对象
 * @returns {string} ->  promise对象 使用.then可以获取base64格式
 */
import { filleToBase64 } from 'lk-tools-lib'
filleToBase64(file)
/**
 * @param {dataurl}  文件base64格式
 * @param {filename} 文件名
 * @returns {file} -> promise对象 使用.then可以获取 将base64转为file的文件对象
 */
import { base64ToFile } from 'lk-tools-lib'
base64ToFile(dataurl, filename)
/**
 * @param {base64} 文件base64格式
 * @param {ratio} 图片压缩比例 0~1之间 一般0.6附近是合理值
 * @returns {string} -> 压缩后的base64格式 
 */
import { dealImage } from 'lk-tools-lib'
dealImage(base64, ratio)

工具

/**
 * @param {obj} 需要循环遍历的对象
 * @param {fn} 回调函数
 * @returns {boolen}  
 */
import { forEach } from 'lk-tools-lib'
forEach(obj,fn)
/**
 * @param {obj} 需要合并的对象
 * @returns {obj}  例如: merge({a:1},{b:2}) return {a:1,b:2}
 */
import { merge } from 'lk-tools-lib'
merge(/*obj1,obj2,....*/)
/**
 * @param {arr} 需要去重的数组对象
 * @param {key} 根据哪个键来去重
 * @returns {boolen}  
 */
import { derepeatArray } from 'lk-tools-lib'
derepeatArray(arr,key)
/**
 * @param {fn} 函数方法
 * @param {wait} 防抖时间
 * @param {immediate} 是否立即执行fn
 * @returns {Function}  
 */
import { debounce } from 'lk-tools-lib'
debounce(fn,wait,immediate)
/**
 * @param {fn} 函数方法
 * @param {wait} 节流时间
 * @returns {Function}  
 */
import { throttle } from 'lk-tools-lib'
throttle(fn,wait)
/**
 * @param {name} 存储的建
 * @param {content} 存储的值
 */
import { setStore } from 'lk-tools-lib'
setStore(name,content)
/**
 * @param {value} 手机号
 * @return { string} 如:formatPhone(13716073435) return 137****3435
 */
import { formatPhone } from 'lk-tools-lib'
formatPhone(value)
/**
 * @return { string}
 */
import { uuid } from 'lk-tools-lib'
uuid()
/**
 * @param {start} 
 * @param {end} 
 * @return { number} 例如 getRandomNumber(1,10) return 1
 */
import { getRandomNumber } from 'lk-tools-lib'
getRandomNumber(start,end)
/**
 * 开启全屏
 */
import { launchFullscreen } from 'lk-tools-lib'
launchFullscreen()
/**
 * 关闭全屏
 */
import { exitFullscreen } from 'lk-tools-lib'
exitFullscreen()
/**
 * 滚动到页面顶部
 */
import { scrollToTop } from 'lk-tools-lib'
scrollToTop()
/**
 * 滚动到指定元素位置 
 * 例如 smoothScroll('#id')
 */
import { smoothScroll } from 'lk-tools-lib'
smoothScroll(domId)
/**
 * @params {value} 需要传到粘贴板里的值
 */
import { copyTextToClipboard } from 'lk-tools-lib'
copyTextToClipboard(domId)
/**
 * 获取字节长度 
 * @params {value}
 */
import { getByteLength } from 'lk-tools-lib'
getByteLength(value)
/**
 * @params {data} object对象
 */
import { parseObject2Url } from 'lk-tools-lib'
parseObject2Url(data)
/**
 *  @params {cname} 键
 *  @params {cvalue} 键值
 *  @params {exdays} 有效的天数
 */
import { setCookie } from 'lk-tools-lib'
setCookie(cname, cvalue, exdays)
/**
 * @params {cname} 键
 */
import { getCookie } from 'lk-tools-lib'
getCookie(data)
/**
 * @params {cname} 键
 */
import { removeCookie } from 'lk-tools-lib'
removeCookie(cname)
import { clearCookie } from 'lk-tools-lib'
clearCookie()

媒体文件

/**
 * @param {fileObj}
 * @return {Promise}
 */
import { getVideosDuration } from 'lk-tools-lib'
getVideosDuration(file)
/**
 * @param {dataUrl} base64格式
 * @param {filename} 文件名
 * @return file
 */
import { downloadBase64File } from 'lk-tools-lib'
downloadBase64File(dataUrl, filename)
/**
 * @param {id} table的表格id
 * @return file
 */
import { exportExcel } from 'lk-tools-lib'
exportExcel(id)

日期

/**
 *  获取某年有多少天
 *  @param {time} 这一年里任意的时间戳
 *  @returns {number} 例如:getYearOfDays(1661421621720) return 365
 */
import { getYearOfDays } from 'lk-tools-lib'
getYearOfDays(1661421621720)
/**
 * 时间格式化。
 * @param {time} 
 * @param {string} option
 * @returns {string} 
 * 如:formatTime(new Date(1661421621720)) -> 2022-08-25 18:00:21
 * formatTime(new Date(1661421621720),"{y}-{m}-{d}") -> 2022-08-25
 * formatTime(new Date(1661421621720),"{y}-{m}-{d} 星期{a}") -> 2022-08-25 星期四
 * 
 */
import { parseTime } from 'lk-tools-lib'
parseTime(time,cFormat)
/**
 * @param {timeStamp} timeStamp 当月的时间戳
 * @returns {Number} 
 */
import { getMonthDays } from 'lk-tools-lib'
getMonthDays()
/**
 *  @param {timeStamp} 时间戳 
 *  @returns {string}
 */
import { getDayWeekday } from 'lk-tools-lib'
getDayWeekday(timeStamp)
/**
 * @param {Object} date日期
 * @returns {Array} 一周的日期
 */
import { getWeekDatesForDate } from 'lk-tools-lib'
getWeekDatesForDate(date)
/**
 *  @param {timeStamp} 时间戳 
 *  @returns {string}
 */
import { getWeekDatesForYMD } from 'lk-tools-lib'
getWeekDatesForYMD(timeStamp)
/**
 * @param {start} 开始日期 
 * @param {diff} n 
 * @returns {string}
 */
import { getDatesAfterWeeks } from 'lk-tools-lib'
getDatesAfterWeeks(start, diff)
/**
 * @param {date} Date对象 
 * @returns {string}
 */
import { isToday } from 'lk-tools-lib'
isToday(date)
/**
 * @param {time} 时间戳
 * @returns {string}
 */
import { getMonthWeek } from 'lk-tools-lib'
getMonthWeek(time)
/**
 * @returns {string}
 */
import { getCurrentWeekday } from 'lk-tools-lib'
getCurrentWeekday()
/**
 * @returns {object} 如:{year: 2022, month: 8, day:22}
 */
import { getCurrentYearMonthDay } from 'lk-tools-lib'
getCurrentYearMonthDay()
/**
 * @param {string} 例如'2022-12-12'
 * @returns {string}
 */
import { getWeekValue } from 'lk-tools-lib'
getWeekValue(dateString)
/**
 * @param {startDate} 如'2022-08-26'
 * @param {enDate} 如'2022-08-28
 * @returns {number} getDaysBetween(2022-08-26', 2022-08-28') -> 2
 */
import { getDaysBetween } from 'lk-tools-lib'
getDaysBetween(startDate, enDate)
/**
 * @param {timeValue} 秒数 如: 3500
 * @returns {string} 例如: formatHMS(3500) -> '58分钟20秒'
 */
import { formatHMS } from 'lk-tools-lib'
formatHMS(timeValue)
/**
 * @param {timeStamp} 出生时间戳
 * @returns {number} 例如: calAgeOfMonth(1577836800000) -> 31
 */
import { calAgeOfMonth } from 'lk-tools-lib'
calAgeOfMonth(timeStamp)
/**
 * @param {identityCard} 身份证号
 * @returns {number} 例如: getAge(372901199806025978) -> 24
 */
import { getAge } from 'lk-tools-lib'
getAge(identityCard)
/**
 * @param {identityCard} 身份证号
 * @returns {number} 例如: getBirthByIdCard(372901199806025978) -> '1998-06-02'
 */
import { getBirthByIdCard } from 'lk-tools-lib'
getBirthByIdCard(id)
/**
 * @param {startTime} 时间戳
 * @param {endTime} 时间戳
 * @returns {number} 
 */
import { getAgeDistance } from 'lk-tools-lib'
getAgeDistance(startTime, endTime)
/**
 * @param {timestamp} 时间戳
 * @param {addDay} 天数
 * @returns {string} 
 */
import { getCurDateAdd } from 'lk-tools-lib'
getCurDateAdd(timestamp, addDay)

校验

/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isNullOrEmpty } from 'lk-tools-lib'
isNullOrEmpty(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isMobile } from 'lk-tools-lib'
isMobile(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isEmail } from 'lk-tools-lib'
isEmail(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { zipCode } from 'lk-tools-lib'
zipCode(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isIdCard } from 'lk-tools-lib'
isIdCard(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isBankCard } from 'lk-tools-lib'
isBankCard(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isNum } from 'lk-tools-lib'
isNum(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { checkUrl } from 'lk-tools-lib'
checkUrl(url)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { formatMoney } from 'lk-tools-lib'
formatMoney(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isArray } from 'lk-tools-lib'
isArray(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isObject } from 'lk-tools-lib'
isObject(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isDate } from 'lk-tools-lib'
isDate(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isNotEmptyArray } from 'lk-tools-lib'
isNotEmptyArray(value)
/**
 * @param {value} 
 * @returns {boolen}  
 */
import { isSrc } from 'lk-tools-lib'
isSrc(url)