1.4.4 • Published 9 months ago

@bj-nsc/functions v1.4.4

Weekly downloads
59
License
MIT
Repository
-
Last release
9 months ago

bj-nsc 公共函数,其中包括防篡改、加解密、数据校验、数据脱敏; ## 安装

npm install @bj-nsc/funcitons

加解密

包括 sm2,sm4,md5,base64 ;

sm2 加解密

import{sm2Decrypt,sm2Encrypt,sm2generateKeyPair} from '@bj-nsc/funcitons';

加解密参数: value:值 必传 key:密钥 有默认密钥值,与 bjnsc 后台密钥配套 不必传 model:模式 默认 1 不必传

获取密钥:

const privateKey = sm2generateKeyPair().privateKey;
const publicKey = sm2generateKeyPair().publicKey;

加解密

const value = 'test';
const envalue = await sm2Encrypt(value,publicKey,model); --加密 model不传默认1 publicKey不传为默认公钥
console.log(envalue);
const devalue = await sm2Decrypt(envalue,privateKey,model); --解密 model不传默认1 privateKey不传为默认私钥
console.log(devalue);

sm4 加解密

import{sm4Decrypt,sm4Encrypt,sm4generateKeyPair} from '@bj-nsc/funcitons';

加解密参数: value:值 必传 key:密钥 有默认密钥值, 不必传

获取密钥:

const key = sm4generateKeyPair()

加解密

const value='test'
const envalue = sm4Encrypt(value,key) --加密 key不传为默认值
console.log(envalue);
const devalue = sm4Decrypt(envalue,key) --解密 key不传为默认值
console.log(devalue)

base64

import{base64Encrypt,base64Decrypt} from '@bj-nsc/funcitons';
const value = 'test';
const envalue = base64Encrypt(value) --加密
const devalue = base64Decrypt(envalue) --解密

md5

import{md5Encrypt} from '@bj-nsc/funcitons';
const value = 'test'
const envalue = md5Encrypt(value) --加密

数据校验

import {checkValue} from '@bj-nsc/functions';
const value = 13125162123;
const type = 'mobile';
const boolen =  checkValue(value,type);
console.log(boolen)
type:
--mobile:手机号
--tele:固定电话
--idcard:身份证
-email:邮箱

数据脱敏

import {encryptValue} from '@bj-nsc/functions';
const value = 13125162123;
const type = 'mobile';
conse newvalue =  encryptValue(value,type);
console.log(newvalue)
type:
--mobile:手机号
--tele:固定电话
--idcard:身份证
--email:邮箱
--bankcard:银行卡
--name:姓名

工具函数

判断数组是否为空

import {isEmptyArray} from '@bj-nsc/functions';
const arr = [];
const isarr  =  isEmptyArray(arr);

判断对象

import {isObject,isEmptyObj} from '@bj-nsc/functions';
const obj={};
const isobj = isObject(obj);//判断是否为对象
const isEmptyobj = isEmptyObj(obj);//判断对象是否为空

延迟函数

import {delay} from '@bj-nsc/functions';
const time=100 ;//延迟时间
const data = 'data'; //data可为任意类型数据
const delaydata = delay(time,data)

生成 UUID

import {guid} from '@bj-nsc/functions';
const uuid = guid();
console.log(uuid)

生成指定长度的随机数

import {getRandom} from '@bj-nsc/functions';
const len = 6;
const random = getRandom(len);
console.log(random);

从对象中获取指定数据

import {pick} from '@bj-nsc/functions';
const obj = {name:'zhangsan',data:{a:14,b:'test',c:[1,2,3,5]}}
const value = pick(obj,'name');
console.log(value) //value值为zhangsan
const value2 = pick(obj, "data","a");
console.log("value2", value2); //value2值为14
const value3 = pick(obj, "data","c",2);
console.log("value", value3); //value3值为3
const obj2 = { name: ['a','b',{a1:'1',b1:'2'}], data: { a: 14, b: "test", c: [1, 2, 3, 5] } };
const value4 = pick(obj2, "name",2,'a1');
console.log("value", value); //value 为1

json 数据转换为 FormData 格式数据,用于 post 接口需要用 formdata 数据请求

import {convertFormData} from '@bj-nsc/functions';
const data = { name: "zhangsan", unit: 10, mobile: "13112341234" };
const formdata = convertFormData(data);
console.log("formdata", formdata);

获取 url 参数、匹配 url 路径

import {getUrlParams,getUrlPath} from '@bj-nsc/functions';
const url =  "http://localhost:8080/#/spa?queryUrl=%7B%22appName%22%3A%22%E9%A1%B9%E7%9B%AE%E6%80%BB%E8%A7%88%22%2C%22";
const query = getUrlParams(url);
console.log("query", query);//返回queryUrl字符串
const matchRouter = getUrlPath(url)
console.log('matchRouter',matchRouter)//返回/#/spa

获取登录消息

import {getTokenInfo,getLoginInfo} from '@bj-nsc/functions';
const userInfo = getLoginInfo();
const token = getTokenInfo;

数据缓存

import {setLocalStorage,getLocalStorageData,setSessionStorage,getSessionStorageData,cleanAppCache,setCookie,getCookie};

const key = 'value';
const test = 'test';
const days = 7;
setLocalStorage(key,value);//存在localstorage
setSessionStorage(key,value);//存在sessionstorage
setCookie(key,value,days);//存在cookie
getLocalStorageData(key)//获取localstorage数据
getSessionStorageData(key)//获取sessionstorage数据
getCookie(key)//获取cookie
cleanAppCache()//清除缓存
deleteCookie(key)//删除特定cookie
1.4.4

9 months ago

1.4.3

9 months ago

1.4.2

9 months ago

1.4.1

9 months ago

1.4.0

9 months ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.30

2 years ago

1.2.23

2 years ago

1.2.24

2 years ago

1.2.22

2 years ago

1.2.27

2 years ago

1.2.28

2 years ago

1.2.25

2 years ago

1.2.26

2 years ago

1.2.29

2 years ago

1.2.21

2 years ago

1.2.20

2 years ago

1.2.18

3 years ago

1.2.19

3 years ago

1.2.16

3 years ago

1.2.17

3 years ago

1.2.15

3 years ago

1.2.14

3 years ago

1.2.12

3 years ago

1.2.13

3 years ago

1.2.8

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.9

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.33

3 years ago

1.0.35

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago