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

public-service

v1.0.2

Published

前端公共方法

Downloads

4

Readme

Functions

transformOptions(data, valueIndex, labelIndex, addAll) ⇒ Array

转换下拉选数据

Kind: global function
Returns: Array - 根据需要生成的select option配置

| Param | Type | Default | Description | | --- | --- | --- | --- | | data | array | | 数据源 | | valueIndex | string | "id" | option的value | | labelIndex | string | "name" | option的label | | addAll | boolean | false | 添加option {value: '', text: '全部'} |

selectLabel(data, value) ⇒ string

设置标签名称

Kind: global function

| Param | Description | | --- | --- | | data | 数据 | | value | 值 |

randomId(length) ⇒ string

生成随机id

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | length | number | 6 | 生成的长度 |

randomColor() ⇒ string

生成随机颜色

Kind: global function
Returns: string - #xxxxxx

checkType(tgt, type) ⇒ boolean

验证数据类型是否为预测类型

Kind: global function

| Param | Type | Description | | --- | --- | --- | | tgt | any | 目标 | | type | string | 预测类型 |

checkTel(value) ⇒ boolean

验证手机号码和座机

Kind: global function

| Param | Type | | --- | --- | | value | number | string |

checkLong(value) ⇒ string | boolean

校验经度是否符合规范

Kind: global function

| Param | Type | | --- | --- | | value | number | string |

checkLat(value) ⇒ string | boolean

校验纬度是否符合规范

Kind: global function

| Param | Type | | --- | --- | | value | number | string |

deepClone(obj) ⇒ object

对象深克隆

Kind: global function

| Param | Type | Description | | --- | --- | --- | | obj | object | 要克隆的对象 |

transformArrayData(data, needColNum, needKey, currentPage, pageSize) ⇒ *

转换表格数据

Kind: global function

| Param | Type | Description | | --- | --- | --- | | data | array | 需要转换结构的源数据 | | needColNum | boolean | 需要增加table序号列数据 | | needKey | boolean | 需要增加唯一标识key | | currentPage | number | 当前页 | | pageSize | number | 每页数据数目 |

arrayByKey(array, key) ⇒ Array

数组根据键名去重

Kind: global function
Returns: Array - 返回筛选后的数组对象

| Param | Type | Description | | --- | --- | --- | | array | array | 需要去重的数组 | | key | string | 指定的根据字段 |

addKey(data, parentKey, newKey) ⇒ *

数组添加key属性

Kind: global function

| Param | Type | Description | | --- | --- | --- | | data | array | 需要转换结构的源数据 | | parentKey | boolean | string | 父元素Key值 | | newKey | boolean | 子元素key |

getDataByKey(data, key) ⇒ array

数组中取出指定的字段

Kind: global function
Returns: array - 返回一维数组

| Param | Type | Description | | --- | --- | --- | | data | array | 数据 | | key | string | 指定键名 |

getTableWidth(columns) ⇒ number

获取表格列配置的总宽度

Kind: global function
Returns: number - table宽度

| Param | Type | Description | | --- | --- | --- | | columns | array | 表格的columns属性 |

getTextWidth(str) ⇒ number

获取文字的宽度

Kind: global function
Returns: number - 列宽度

| Param | Type | Description | | --- | --- | --- | | str | string | 文字 |

paramSerializer(params) ⇒ *

拼接参数

Kind: global function
Returns: * - 返回导出拼接字符串

| Param | Type | Description | | --- | --- | --- | | params | object | 导出文件所需参数 |

setCookie(c_name, value)

cookie存值

Kind: global function

| Param | Type | Description | | --- | --- | --- | | c_name | string | 要保存字段的名称 | | value | string | 要保存字段的值 |

getCookie(c_name) ⇒ string

cookie取值

Kind: global function
Returns: string - 返回字段对应的值, 若字段不存在则返回空

| Param | Type | Description | | --- | --- | --- | | c_name | string | 要取得的字段名 |

clearCookie(name)

cookie删值

Kind: global function

| Param | Type | Description | | --- | --- | --- | | name | string | 要清空的字段名 |

getLocalStorage(field, fieldName)

localStorage 取值

Kind: global function

| Param | Type | Description | | --- | --- | --- | | field | string | 要获取的对象信息 | | fieldName | string | 要获取的对象中的信息 |

arrDataBy(arr, key, where) ⇒ array

将数组按键名取出单一值可配置条件

Kind: global function
Returns: array - 一维数组

| Param | Type | Description | | --- | --- | --- | | arr | array | 目标数组 | | key | string | 取出数据的属性名 | | where | function | string | () |

arrByKey(arr, arr2, keys) ⇒ array

循环两组数据,根据条件返回新的数组

Kind: global function
Returns: array - 符合条件的数据

| Param | Type | Description | | --- | --- | --- | | arr | array | 目标数组 | | arr2 | array | 数组2 | | keys | array | 条件名称 |

arrToKeyData(arr, keys, exclude) ⇒ array

将数组根据目标键名中取出或排除该字段

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | arr | array | | 目标数组 | | keys | array | | 目标键名 | | exclude | boolean | false | 是否为排除目标键名模式,默认为false; false: 按键名获取字段; true: 获取键名以外的字段 |

arrGroupBy(arr, key) ⇒ array

将对象数组按照对象某一属性分组

Kind: global function

| Param | Type | Description | | --- | --- | --- | | arr | array | 目标数组 | | key | string | 分组根据的属性名 |

transformTime(startTime, endTime, format, symbol) ⇒ string

开始结束时间转换显示

Kind: global function
Returns: string - 返回字符"YYYY~YYYY"

| Param | Type | Description | | --- | --- | --- | | startTime | object | string | 开始日期 | | endTime | object | string | 结束日期 | | format | string | 格式化 | | symbol | string | 转换符号 |

getQueryString(name) ⇒ string | null

获取url拼接的参数

Kind: global function

| Param | Type | | --- | --- | | name | string |

getDistance(lonLat, lonLat2) ⇒ number

获取两个坐标之间的距离

Kind: global function

| Param | Type | Description | | --- | --- | --- | | lonLat | object | 坐标{longitude, latitude} | | lonLat2 | object | 坐标{longitude, latitude} |

BD09ToGCJ02(lng, lat) ⇒ array

百度坐标转高德坐标

Kind: global function
Returns: array - 经纬度一纬数组

| Param | Type | Description | | --- | --- | --- | | lng | number | string | 经度 | | lat | number | string | 纬度 |

GCJ02ToBD09(lng, lat) ⇒ array

高德坐标转百度坐标

Kind: global function
Returns: array - 经纬度一纬数组

| Param | Type | Description | | --- | --- | --- | | lng | number | string | 经度 | | lat | number | string | 纬度 |

GCJ02ToWGS84(lng, lat) ⇒ array

高德坐标转天地图坐标

Kind: global function
Returns: array - 经纬度一纬数组

| Param | Type | Description | | --- | --- | --- | | lng | number | string | 经度 | | lat | number | string | 纬度 |

WGS84ToGCJ02(lng, lat) ⇒ array

天地图坐标转高德坐标

Kind: global function
Returns: array - 经纬度一纬数组

| Param | Type | Description | | --- | --- | --- | | lng | number | string | 经度 | | lat | number | string | 纬度 |

uploadFile(param, name, serverURL, type) ⇒ Promise

自定义上传文件

Kind: global function

| Param | Type | Description | | --- | --- | --- | | param | object | 上传参数 | | name | string | 上传字段名称 | | serverURL | string | 上传地址 | | type | string | 文件类型 |

setWebTitle(title)

修改网页标题

Kind: global function

| Param | Type | Description | | --- | --- | --- | | title | string | 标题 |

setWebIcon(link)

修改网页图标

Kind: global function

| Param | Type | Description | | --- | --- | --- | | link | string | 图标地址 |

transformFileSize(limit) ⇒ string

转换字节单位

Kind: global function

| Param | Type | Description | | --- | --- | --- | | limit | number | 大小 |

stringToEllipsisText(text, length) ⇒ string

文本超出数量省略号显示

Kind: global function

| Param | Type | Description | | --- | --- | --- | | text | string | 文本内容 | | length | number | 要省略文本长度(不传默认为10) |

autoFullScreen()

自动全屏

Kind: global function

fullScreen(element)

浏览器全屏

Kind: global function

| Param | Type | Description | | --- | --- | --- | | element | element | 节点 |

outFull()

取消全屏

Kind: global function

debounce(action, delay) ⇒ function

防抖函数

Kind: global function

| Param | Type | Description | | --- | --- | --- | | action | function | 函数(要进行防抖的函数) | | delay | number | 传入的毫秒,在这也就是延迟时间 |

throttle(action, wait) ⇒ function

节流函数

Kind: global function

| Param | Type | Description | | --- | --- | --- | | action | function | 要执行的方法 | | wait | number | 等待的时长 |

getSessionItem(sessionName, name) ⇒ string

返回localStorage中的用户信息

Kind: global function

| Param | Type | Description | | --- | --- | --- | | sessionName | string | 要获取的对象信息 | | name | string | 要获取的对象中的信息 |

validAccessBtn(accessCode, key) ⇒ boolean

验证按钮权限

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | accessCode | string | | 按钮权限编码 | | key | string | "accessBtn" | localStorage 存储键名 |

getAccessBtn(key) ⇒ *

获取菜单按钮

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | key | string | "accessBtn" | localStorage 存储键名 |

validAccessMenuBtn(menuCode, accessCode, key) ⇒ boolean

验证菜单按钮权限

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | menuCode | string | | 菜单编码 | | accessCode | string | | 菜单权限编码 | | key | string | "accessMenuBtn" | localStorage 存储键名 |

getAccessMenuBtn(menuCode, key) ⇒ boolean

获取菜单按钮

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | menuCode | string | | 菜单编码 | | key | string | "accessMenuBtn" | localStorage 存储键名 |

millisecondToDate(result) ⇒ string

毫秒转天-小时-分

Kind: global function

| Param | Type | Description | | --- | --- | --- | | result | number | 毫秒数 |

floatNumber(value, float) ⇒ string

小数截取

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | value | number | | 数值 | | float | number | 2 | 截取长度 |