@TOC
封装一些常用的JavaScript功能,提高开发效率。
npm install js-jf-utils
yarn add js-jf-utils
如果网络不好且没有cnpm可以试试这个(强烈建议不要使用cnpm和下列方式)
npm install js-jf-utils --registry=https://registry.npmmirror.com
序号 | 方法名 | 描述 |
---|---|---|
01 | jsMjJsonString | JSON字符串 |
02 | jsMjShallClone | 浅克隆 |
03 | jsMjIndexOf | 查询字符 |
04 | jsMjType | 数据类型 |
05 | jsMjIsType | 判断数据类型 |
06 | jsMjNullObject | 空对象 |
07 | jsMjNullArray | 空数组 |
08 | jsMjPureArray | 纯数组 |
09 | jsMjArrayObject | 数组对象 |
10 | jsMjParentNode | 根据id获取该节点的所有父节点id |
11 | jsMjToStringt | 转换成字符串 |
12 | jsMjCreateText | 通过十进制数值生成文字 |
13 | jsMjCreateRandom | 生成随机数 |
14 | jsMjUnique | 生成随机唯一值 |
15 | jsMjToTree | 扁平数组转树形 |
16 | jsMjToFlat | 树形JSON转为扁平数组 |
17 | jsMjRandReco | 数组随机重组 |
18 | jsMjCheckMobiPhon | 实时校验手机号 |
19 | jsMjCheckCurr | 实时校验货币 |
20 | jsMjCheckNumbLett | 实时校验大写、小写、数字 |
21 | jsMjCheckNumbLettLine | 实时校验大写、小写、数字和横线 |
22 | jsMjCheckNozh | 实时校验非汉字输入 |
23 | jsMjCheckNumber | 实时校验非数字输入 |
CDN
<!-- 导入 -->
<script src="xxx/js-mj-utils/index.js"></script>
<script>
let { jsMjToStringt } = jsMjUtils;
// 解构使用
console.log(jsMjToStringt(['status', 'type'], {
name: 'MJ',
age: 25,
status: 1,
type: 0
}));
// {name: 'MJ', age: 25, status: '1', type: '0'}
// 直接使用
let result = jsMjParentNode(
[
{
id: 'a1',
parentId: undefined,
name: 'MJ1',
age: 25,
status: 0,
type: 2,
children: [
{
id: 'b2',
parentId: 'a1',
name: 'MJ2',
age: 18,
status: 1,
type: 0,
children: []
}
]
},
{
id: 'c3',
parentId: undefined,
name: 'MJ3',
age: 20,
status: 2,
type: 1,
children: [
{
id: 'd4',
parentId: 'c3',
name: 'MJ4',
age: 25,
status: 1,
type: 0,
children: [
{
id: 'e5',
parentId: 'd4',
name: 'MJ5',
age: 23,
status: 3,
type: 1,
children: [
{
id: 'f6',
parentId: 'e5',
name: 'MJ6',
age: 23,
status: 3,
type: 1,
children: [
{
id: 'g7',
parentId: 'f6',
name: 'MJ7',
age: 30,
status: 3,
type: 1,
children: []
}
]
},
{
id: 'h8',
parentId: 'e5',
name: 'MJ8',
age: 23,
status: 3,
type: 1
}
]
},
{
id: 'i9',
parentId: 'd4',
name: 'MJ9',
age: 25,
status: 3,
type: 1,
children: []
}
]
}
]
}
],
(item) => item.id === 'i9'
);
console.log('result: ', result);
// ['i9', 'd4', 'c3']
</script>
vue
在main.js中引入
import 'js-mj-utils'
使用方式与CDN一致(建议直接使用,不要解构)