# format-function

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

Latest version **2.0.5** (published 2023-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install format-function
pnpm add format-function
yarn add format-function
bun add format-function
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2023-08-09 |
| First published | 2021-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | lhc-soul |

## Links

- npm: https://www.npmjs.com/package/format-function
- npm.io page: https://npm.io/package/format-function

## Dependencies (2)

- [dayjs](https://npm.io/package/dayjs.md) ^1.10.7
- [clipboard](https://npm.io/package/clipboard.md) ^2.0.8

## Recent versions

- 2.0.5 (latest) — 2023-08-09
- 2.0.4 — 2022-09-07
- 2.0.3 — 2022-08-27
- 2.0.2 — 2022-03-13
- 2.0.1 — 2022-03-13
- 2.0.0 — 2022-03-13
- 1.0.43 — 2022-02-27
- 1.0.41 — 2022-02-27
- 1.0.40 — 2022-02-27
- 1.0.39 — 2022-02-27
- 1.0.38 — 2022-02-27
- 1.0.37 — 2022-02-27
- 1.0.36 — 2022-02-26
- 1.0.35 — 2022-02-26
- 1.0.34 — 2022-02-26
- … 34 more at https://npm.io/package/format-function/versions

## README

## URL

```js
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

```js
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为根据对象的字段去重

```js
import {array} from "format-function";
array()
```



### string

```js
import {strStart,strEnd} from "format-function";

strStart(string,start)		判断字符串是否以特定开头，返回一个布尔值
strEnd(string,start)		判断字符串是否以特定结尾，返回一个布尔值
```



### object

```js
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

```js
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

```js
import {
   getSingleEle,
   getAllEle
} from "format-function";

getSingleEle(selector)		获取单个dom元素，selector为css选择器，返回值为一个dom元素
getAllEle(selector)			获取dom元素集合，selector为css选择器，，返回值为一个dom元素集合
```



### 偏移量

```js
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为距离
```



# 复制文本

```js
import { copyText } from "format-function";
copyText(text,success,error)	复制文本，text为要复制的文本内容，success,error为回调函数
```



# imgToBase64

```js
import { imgToBase64 } from "format-function";
imgToBase64(file)	img图片文件转化base64，返回值为base64数值
```



# downloadBlob

```js
import { downloadBlob } from "format-function";
downloadBlob(blob,filename,success)				
```

---
_Source: https://npm.io/package/format-function · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
