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

format-function

v2.0.5

Published

```js import {getRouterQuery,query,setUrl} from "format-function";

Downloads

162

Readme

URL

import {getRouterQuery,query,setUrl} from "format-function";

getRouterQuery()				获取URL上的参数,哈希和历史路由都适用
query							是getRouterQuery的返回值
openNewPage(url)				打开一个新的窗口

setUrl(url,query,is_cover)		
	设置url,url为一个完整的url,可包含参数,query为一个对象,is_cover为一个布尔值,当url上的参数query有相同时,query是否覆盖url的参数值,默认值为true,覆盖

localStorage

主要是简化设置storage

import {store} from "format-function";
store.set(name,value)
store.get(name)
store.remove(name)
store.clearAll()

object

array

执行后将会在数组的原型链上追加两个方法,分别是delete、insert,unique,uniqueObject方法。delete(index),index为要删除的索引。insert(index,arr),index为要插入的位置,arr为数组,存放插入的元素。unique方法只是简单的数组去重,使用Array.from(new Set(this))实现。uniqueObject(prop)方法,数组对象去重,prop为根据对象的字段去重

import {array} from "format-function";
array()

string

import {strStart,strEnd} from "format-function";

strStart(string,start)		判断字符串是否以特定开头,返回一个布尔值
strEnd(string,start)		判断字符串是否以特定结尾,返回一个布尔值

object

import {getObjectKey,getObjectValue,getObjectParse,getObjectString,deepClone} from "format-function";

getObjectKey(object)		获取对象的属性,返回值为一个数组
getObjectValue(object)		获取对象的属性值,返回值为一个数组
getObjectParse(object)		转换成json对象,返回值为json对象
getObjectString(object)		转换成json字符串,返回值为json字符串

deepClone(origin,target)	深拷贝,origin为原对象,target为目标对象,返回一个对象

DOM

CSS

import {
   setSingleEleCss,
   setAllEleCss,
   getSingleEleCss,
   getEleAllCss
} from "format-function";

setSingleEleCss(ele,style)
	设置单个元素的css样式,ele为要操作的单个dom元素,style为样式对象,例如{width:"50px"},无返回值
    
setAllEleCss(ele,style)
	设置多个元素的css样式,ele为要操作的dom元素集合,style为样式对象,例如{width:"50px"},无返回值

getSingleEleCss(selector,field)
	selector为css选择器,field为要获取的字段的值

getEleAllCss(selector)
	selector为css选择器,获取css全部的样式

DOM

import {
   getSingleEle,
   getAllEle
} from "format-function";

getSingleEle(selector)		获取单个dom元素,selector为css选择器,返回值为一个dom元素
getAllEle(selector)			获取dom元素集合,selector为css选择器,,返回值为一个dom元素集合

偏移量

import {
   getEleScrollTop,
   getPageScrollHeight,
   getIsTouchBottom,
   getEleClientWidth,
   getEleClientHeight,
   getEleOffsetTop,
   getEleOffsetParent,
   getEleOffsetHeight,
   getEleOffsetWidth,
   setEleScrollTop
} from "format-function";

getEleScrollTop()				获取页面滚动条的滚动距离,返回值为滚动距离
getPageScrollHeight()			获取窗口实际高度,返回值为窗口实际高度
getIsTouchBottom(ele,distance)	判断滚动是否触底,ele为要操作的单个dom元素,distance距离底部多少触发,返回值为一个布尔值
getEleClientWidth(selector)		获取元素的clientWidth
getEleClientHeight(selector)	获取元素的clientHeight
getEleOffsetTop(selector)		获取元素的offsetTop
getEleOffsetParent(selector)	获取元素的offsetParent
getEleOffsetHeight(selector)	获取元素的OffsetHeight
getEleOffsetWidth(selector)		获取元素的OffsetWidth
setEleScrollTop(selector,top)	top为距离

复制文本

import { copyText } from "format-function";
copyText(text,success,error)	复制文本,text为要复制的文本内容,success,error为回调函数

imgToBase64

import { imgToBase64 } from "format-function";
imgToBase64(file)	img图片文件转化base64,返回值为base64数值

downloadBlob

import { downloadBlob } from "format-function";
downloadBlob(blob,filename,success)