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 🙏

© 2026 – Pkg Stats / Ryan Hefner

f-com

v1.8.1

Published

开发中常用到的工具及组件

Downloads

15

Readme

开发常用到的工具集合

支持typescript

usage

npm install f-com

or

yarn add f-com
import fCom from 'f-com

if(fCom.isMobile) { ... }

import { isMobile } from 'f-com'

微信小程序版

微信小程序版本去掉一些小程序中不支持的浏览器接口,并且添加一些wx相当接口。

npm install f-com --production

typescript支持:

// tsconfig.json 添加类型引用
{
  "compilerOptions": {
    ...
    "paths": {
      "f-com": ["node_modules/f-com/miniprogram_dist/types.d.ts"]
    }
  }
}

数组(以下为文档)

去重

import { arrayRemoveRepeat, ... } from 'f-com'
arrayRemoveRepeat([{id: 1}], 'id') // 跟椐id值去重

浏览器相关

  • isMobile
  • isWeiXin
  • isIos
  • isMinProgram
import { isMobile, isWeiXin, isIos, isAndroid, isXiaoMi, isMiniProgram isIE, isIE9, isEdge, isChrome, isFF } from 'f-com'

// 只有isMiniProgram 是一个函数
// 是否为微信小程序
if(isMiniProgram()) { ... }

// 是否为移动端
if(isMobile) { ... }

// 微信浏览器
if(isWeiXin) { ... }
// firefox
if(isFF) { ... }

String

  • param2Obj: 将url中的参数转成 key value 对像(依据?)

    fCom.param2Obj('http://localhost:3000/productions/index.html?a=1&b=2&c=3') // { a: 1, b: 2, c: 3 }
  • body2Obj: 将类a=1&b=2 转换为 key value 对像(无需?)

    fCom.body2Obj('a=1&b=2&c=3') // { a: 1, b: 2, c: 3 }
  • fileLastName(src, [defaultName]): 查找文件后缀名(带.)

    fCom.fileLastName('iiiimage.jpg') // .jpg
  • mosaicEmail(emailAddress[, mosaicFront, mosaicEnd]): 为邮箱地址打上*号马赛克, 默认'@'前字符替换

    mosaicEmail('[email protected]') // fc****[email protected]
    mosaicEmail('[email protected]', true, true) // fc****l@ou****k.com
    mosaicEmail('[email protected]', false, true) // fcomtill@ou****k.com
    mosaicEmail('[email protected]', false, false) // [email protected]

Time时间

  • readableTime(time): 格式化为可读时间(xx秒前, XX分钟、小时、天、个月、年前)

    fCom.readableTime('1601185700124') // 5分钟前

文件内容等

  • imgSrc2base64(src) : url图片资源转换为base64编码

    fCom.imgSrc2base64('http://img.jpg').then(res => { ... })
    // or
    let base64 = await fCom.imgSrc2base64('http://img.jpg')
  • dowloadImage({ src, zip = false, JsZip }): 下载图片资源

    // 当使用打包下载时必须传入jszip
    // npm社区的jszip @3.5.0,由于rollup打包出错,改为外置 see https://github.com/Stuk/jszip#readme
    import JsZip from 'jszip'
    // 	直接下载
    fCom.dowloadImage({ src: 'http://img.jpg' })
      
    // do
    fCom.dowloadImage({ src: 'http://img.jpg', zip: true, JsZip })
      
    // 多个src, 打包下载
    fCom.dowloadImage({ src: ['http://a.jpg', 'http://b.jpg'], zip: true, JsZip })

Number

  • keep2Decimals(num, [mathod]): 保留两位小数默认用Math.floor方法,可转入mathod(Math的方法名)

Object

  • logGitInfo(infoObj[, color1 = '#1475b2', color2 = '#42c02e']): 带样式打印对象key value于浏览器端

GPS坐标系间的转换

  • transB2T(longitude, latitude) 百度转腾讯(高德、谷歌)
transB2T(113.819326, 22.630472)
// { longitude: 113.xxx, latitude: 22.xxxx }
  • transT2B(longitude, latitude) 腾讯转百度

  • wgs84tobd09 wgs84坐标转bd09坐标(bd09为百度坐标系)

  • wgs84togcj02 wgs84转gcj02(gcj02为高德、腾讯、谷歌坐标系)