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

use-tools-before

v1.0.9

Published

常用的工具函数

Downloads

673

Readme

常用的工具函数

引用方法

1. copyTextToClipboard

描述

将指定文本复制到剪贴板

不能使用navigator.clipboard时使用

使用方法

copyTextToClipboard({text : '想要复制的文本'})
			.then((result) => {
				//复制成功
			})
			.catch((error) => {
				//复制失败
			})

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | text | 要复制的文本 | string | '' | | success | 成功时的回调函数 | Function | - | | error | 失败时的回调函数 | Function | - |

2. invokeStr

描述

在js里面运行字符串

使用方法

invokeStr('100 > 50')

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | fn | 要复制的文本 | string | '' | | objData | 成功时的回调函数 | objDataType | {} |

3. domScroll2FirstClass

描述

在某个class上滚动到某个指定class类第一个元素上

使用方法

domScroll2FirstClass('.domClass','.scrollDomClass')

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | domClass | 父级class | string | | | scrollDomClass | 指定class | string | | | block | | start , center , end , nearest | center | | behavior | | auto, instant, smooth | auto | | inline | | start , center , end , nearest | nearest |

4. getFileNameInContentDisposition

描述

在content-disposition中获取文件名filename

使用方法

getFileNameInContentDisposition('attachement;filename=qwe.txt;hahahaaha')

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | contentDisposition | header中的content-disposition | string | |

5. saveAs

描述

保存函数

使用方法

saveAs(blob,'text.txt')

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | blob | blob文件流 | string | | | filename | 文件名 | string | |

6. sortTableFunction

描述

第一版表格行拖拽

使用方法

	<el-table
    ref="tabA"
    class="elTable"
    :data="newList"
  >
    <el-table-column
      label="排序号"
      width="150px"
      align="center"
      fixed
      prop="num"
    >
      <template #default="scope">
        <div
          style="display: flex; align-items: center"
          :attrname="scope.row.num"
          class="sortclass"
        >
          <span style="margin-left: 10px">{{ scope.row.num }}</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column
      label="姓名"
      fixed
      align="center"
      prop="name"
    />
  </el-table>
let dataList = ref([])

const changeDataFun = (dataList) => {
  const reOrList = toRaw(dataList).map((item, idx) => {
		return {
			num: idx + 1,
			name: item.name,
		}
	})
	return reOrList
}

sortTableFunction(dataList,changeDataFun,'sortclass','attrname')

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | newList | 列表的数据项 | array | | | changeDataFun | 一个修改数据项的函数(选填) | Function | null | | sortclass | 想要拖拽的类名diySorttrue时使用 | string | sortclass | | attrname | 推拽相关的一个自定义属性diySorttrue时使用 | string | attrname |

7. dragTableFun

描述

第二版表格拖拽

使用方法

let tableList = ref([])
dragTableFun().rowDrop(tableList)

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | dataList | 表格数据 | Array | | | fatherDom | 父级Clacc | string | .draggable .el-table__body-wrapper tbody | | sonDom | 子级Class | string | .draggable .el-table__row |

8. flattenTreeData

描述

对象数组扁平化

使用方法

let data = [
	{
		name: '1',
		children: [
			{
				name: '1-1',
				children: [],
			},
			{
				name: '1-2',
				children: [
					{
						name: '1-2-1',
						children: [],
					},
					{
						name: '1-2-2',
						children: [],
					},
				],
			},
		],
	},
	{
		name: '2',
		children: [],
	},
]
flattenTreeData(data, 'children')

参数说明

| 名称 | 说明 | 类型 | 默认值 | | ------------- | :-----------: | :-----------: | :-----------: | | arr | 对象数组数据 | any[] | | | key | 想要递归的key值 | string | children |