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

jsbusiness

v1.1.2

Published

常用的js函数封装,包含BOD,DOM,Node,uni-app

Downloads

21

Readme

安装

npm install jsbusiness

源码地址

引用方式 (按需引用)

import * as UniHttp from 'jsbusiness/UniHttp' // uni-app 请求
import * as UtilDate from 'jsbusiness/UtilDate'  // js 时间相关函数
import * as UniUtil from 'jsbusiness/UniUtil'  // uni-app 函数
import * as NodeUtil from 'jsbusiness/NodeUtil' // Node.js 函数库
import * as NavigatorUtil from 'jsbusiness/NavigatorUtil' // 浏览器对象 Navigator 函数
import * as UtilityBox from 'jsbusiness/UtilityBox' // 常用函数封装 使用 JavaScriptrunTime
import * as EncryptionToDecrypt from 'jsbusiness/EncryptionToDecrypt' // 加密函数库
import * as UtilString from 'jsbusiness/UtilString'  // 字符串相关函数

CSDN 博客地址

使用对应函数可以进行解构后在使用

import { timeToDate, navigator, functions } from 'jsbusiness';
const { getDateDiff } = timeToDate;
const { getCookie } = navigator;
const { isType, randomCoding } = functions;
getDateDiff('2021-10-10 10:00', '2021-10-10 12:00:02', 'minute');
getCookie('token'); //xxxxx
isType({}); // 'Objext'
randomCoding(6); // 195658

| 函数名称 | 使用环境 | 函数描述 | | ---------- | --------------- | --------------------------------------------------------------------------------------------- | | timeToDate | Node.JS,浏览器 | 获取时间,获取当前时间,获当前周,时间相关获取函数 | | navigator | 浏览器 | 只能在浏览器运行的函数,比如 DOM,判断当前网络是否可用,sessionStorage,localStorage 等函数封装 | | functions | Node.JS,浏览器 | 常用函数,节流防抖 |

timeToDate(日期时间相关函数)

getData(optional) 获取当前时间 返回格式 '2021-10-11 14:58:02'

optional(string) 可选参数

date 返回当前年月日

tiem 返回当前时分秒

formatTime(time,Division) 格式字符串时间

formatTime(20211011151222, '-'); // '2021-10-11 15:12:22'
filterTime(20211011151222, '/'); //'2021/10/11 15:12:22'

secondsConversion(time) 秒转化为 小时-分钟-秒

secondsConversion(5000)  01h23min20s
secondsConversion(500)   08min20s
secondsConversion(50)   50s

getDateDiff (str,end,type)对比二个时间返回差

str 开始时间

end 结束时间

type( second 秒 minute 分 hour 小时 day 天) 对比类型

getDateDiff('2021-10-10 10:00', '2021-10-11', 'hour')  14
getDateDiff('2021-10-10 10:00', '2021-10-10 12:00:02', 'second')  7202
getDateDiff('2021-10-10 10:00', '2021-10-10 12:00', 'second')  720
getDateDiff('2021-10-10 10:00', '2021-10-10 12:00:02', 'minute') 120

getWeekDate 获取当前周几

getWeekDate() //星期三

weekTime 获取当前天的周一到周末的年月日

weekTime()[
  ('2021/10/11',
  '2021/10/12',
  '2021/10/13',
  '2021/10/14',
  '2021/10/15',
  '2021/10/16',
  '2021/10/17')
];

monday 获取本周周一年月日

monday() 2021-10-11

sunday 获取本周日 的时间

sunday() 2021-10-17

getCurrentMonthFirst 获取本月的第一天

getCurrentMonthFirst() 2021-10-01

getCurrentMonthLast 获取本月的最后一天

getCurrentMonthLast() 2021-10-31

timeFormatsss 格式化中国标准时间

timeFormatsss(new Date())  2021-10-11 00:00:00

functions (常用函数)

positionToCalculate(lat1, lng1, lat2, lng2) 计算二个经纬度的距离

positionToCalculate(106.233366, 29.602296, 106.452697, 29.61134) 24.417公里
positionToCalculate(106.589688, 29.565987, 106.592563, 29.569765) 342米

debounce(cb,tiem) 防抖函数

cb 回调函数 必填 tiem 防抖时间 默认 500

debounce();

throttle(cb,tiem) 节流:规定在一个单位时间内,只能触发一次函数。如果这个单位时间内触发多次函数,只有一次生效

cb 回调函数 必填 tiem 防抖时间 默认 500

throttle();

isFunc(Func,objFunc) 判断当前是不是一个函数 如果是就执行,

Func | function 可选 objFunc | 参数任意,如何是函数就执行

isFunc();

MatchingProtocol(str) 匹配字符中是否存在多个 http 地址

str | String 必传 返回一个对象 true 为一个 false 为个

MatchingProtocol()  false

countDown(item = 60, running, finish) 倒计时

item | Number 必填 倒计时时间 running | function 必填 正在倒计时中得会执行得函数 finish |function 可选 倒计时结束执行得函数

返回倒计时时间 ID 用于 clearInterval 来停止

回调参数 stop, item stop 用于停止的 ID item 当前倒计时的秒

countDown(
  60,
  () => {
    stop, item;
  },
  (stop, item) => {}
);

isType 返回当前数据的数据类型

isType(1)  'Number'
isType(false) 'Boolean'
isType({})  'Object'
isType(new Date())  'Date'
isType(()=>{})  'Function'
isType(undefined)   'Undefined'
isType(null)    'Null'

hexadecimal(color) 判断是否是 16 进制颜色

color | string 必填

hexadecimal('#CCCCCC');

randomCoding(max) 随机数反回

max |number 默认值 6

randomCoding()  '123DFg'

ToIdentify(ar) 伪类数组鉴别以及转换

ar |Arrar 必填 返回为真数组

ToIdentify()  false

navigator 浏览器相关的函数

conver 计算图片的大小

conver();

debugging({ Noright = true, NoKeyDown = true, debug = true}) 获取 Cookie

Noright | Boolean 默认 true 禁止鼠标右键 NoKeyDown | Boolean 默认 true 禁禁止 F12 debug | Boolean 默认 true 反调试代码

debugging();

getCookie(name)

获取 Cookie

name | string 必填 返回对应得 key 值

getCookie('name'); // xx

runtimeEnvironment

获取当前浏览器运行环境 是微信,支付宝,安卓,IOS,PC,移动,H5

console.log(new runtimeEnvironment()); /* getDeviceType: ƒ (type)
                                    iosSystem: false //ios系统
                                    isAliPay: false //  支付宝客服端
                                    isAndroidSystem: false // 安卓系统
                                    isMobile: true // 是否是移动端 某些情况下获取不准确 建议使用
                                    isPc: true //判断是否是pc
                                    isWX: false // 是否在微信客户端
                                    userAgent: "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/104.0.0.0 safari/537.36"
                                    */
// getDeviceType 有一个可参数,传入后返回具体的终端类型 ,不传入,返回模糊的终端
new runtimeEnvironment().getDeviceType('type'); //Android || iPhone || PCend
new runtimeEnvironment().getDeviceType(); //mobile || PCend

applicationStorage(**params **)

存储 sessionStorage 或 localStorage

params 参数说明

| 参数 | 数据类型 | 是否必填 | 参数说明 | | -------- | -------- | ----------------------------------- | ------------- | | key | Boolean | N (默认值 false) | key 是否加密 | | data | Boolean | N(默认值 false) | data 是否加密 | | type | String | N(默认值 local ,可选择 session ) | 存储类型 | | overtime | Boolean | N | 超时删除 |

代码示例

基本使用 实例化存储类

const storage = new applicationStorage(false, true);

存储数据

const storage = new applicationStorage(false, true);
storage.setSession('name', 'selfsummer');
console.log(storage.getSession('name'));

设置超时时间 (1S=1000)

const storage = new applicationStorage(true, true, 'local', true);
storage.setSession('name2', { name: 'selfsummer', age: 12 }, 5000); // 5000 = 5秒

删除指定 applicationStorage().removeItem

| 参数 | 参数说明 | | ---- | ---------- | | key | 存储的 key |

new applicationStorage().removeItem('key');

删除所有

storage.removeAll();

getNetwork(cb) 获取当网络

const { getNetwork } = navigator;
getNetwork(); // 获取当前网络
getNetwork((net) => {
  // 网络变化时触发回调函数
  // net=> {
  /* Details: { 
          downlink // 下载速度
          effectiveType // 网络类型
          rtt  连接预估往返时间 值越小网速越快
          },
        BeforeType // 切换前的
        CurrentType  // 切换后的
        Available // 当前网络是否可用
  	}*/
});

downlinkhe和rtt返回值描述

FileSelection 文件相关

入参接口类型

imageType = "image/png" | "image/jpeg" | "image/webp"

处理后返回

NewPictures

NewPictures = {
PreviewUrl: *String* 预览地址
 data: *String*  base64图片
 file: *File*  可上传的图片
}

FileSelection 文件选择类

FileSelection.openFiles(Option,fileProcessing)

openFiles 文件选择

Option 说明

| key | 类型 | 说明 | | --------------- | ---------- | ------------------------------------------------------------ | | multiple | Boolean | 是否支持多选 | | accept | MimeType | 接受的文件类型 audio/, 表示 “任何音频文件”。video/,表示 “任何视频文件”。 | | capture | "camera" | "user" | | webkitdirectory | Boolean | 选择一个目录(或多个目录,如果 multiple 也出现的话) |

fileProcessing 选择文件后操作 可选值

| 可选值 | | | | ------------- | ------------ | ---- | | VideoCover | 获取视频奋勉 | | | reading | 文件读取 | | | compressImage | 图片压缩 | | | preview | 文件预览 | |

打开文件选择

FileSelection.openFiles(InputFileOpentin)

InputFileOpentin 参数描述

| key | 默认值 | 描述 | | --------------- | ------ | -------------------------------------------------------------------------------------------------------------------------- | | multipl | null | 是否支持多选 | | accept | null | 接受的文件类型 audio/, 表示 “任何音频文件”。video/,表示 “任何视频文件”。 image/*,表示 “任何图片文件”。 | | capture | null | camera (默认打开后置) 打开摄像头 user 打开前置摄像头 camcorder 打开录像 microphone 打开录音机 environment 打开后置摄像头 | | webkitdirectory | null | 选择一个目录(或多个目录,如果 multiple 也出现的话) | | | | | | | | |

InputFileOpentin 配置

打开相机拍照

capture 兼容问题

IOS 打开前置 Android 打开后置 user 属性 IOS 打开前置 Android 打开后置

FileSelection.openFiles({
  multipl: false,
  accept: 'image/*',
  capture: 'user',
});

打开相机录像

FileSelection.openFiles({
  multipl: false,
  accept: 'video/*',
  capture: 'user',
});

打开录音机

IOS 会打开相机但是会申请麦克风权限,Android 会直接打开录音

FileSelection.openFiles({
  multipl: false,
  accept: 'audio/*',
  capture: 'microphone',
});

获取相机和文件系统(默认)

FileSelection.openFiles({ accept:'image/*'})

文件切片 FileShardRead

| 参数 | 描述 | | ---- | ------------------- | | File | File 类型或者二进制 |

返回 FormData

FileSelection.FileShardRead(File)

预览文件 FilePreview

返回值 Bloburl

FileSelection.FilePreview(files: File | Blob | Array<File>)

释放预览 releasePreview

在预览完成后不需预览 销毁预览链接,因为是在内存中,会增加内容负担

图片压缩 photoCompression

返回 NewPictures

photoCompression(src: string, w = 200, h = 200, type: imageType = 'image/png', quality = 0.95)

获取视频中的某一个帧做封面 getVideofirstFrame

| key | 默认值 | 说明 | | ------- | ------ | --------------------------- | | file | 无 | 选中的文件内容 | | frame | 5 | 取第几帧做封面 0 可能为黑屏 | | | | |

getVideofirstFrame(files: File, frame: number = 5)

download 文件下载

参数说明

| key | 描述 | | -------- | ------------------------------------ | | link | 图片链接 | | fileName | 下载出来的文件名称(默认“保存文件”) | | | |

链接内容下载

aLink

new download().aLink(link: string, fileName?: string)

使用 http 请求下载内容

dwHttpRequest

new download().dwHttpRequest(link: string, fileName?: string)

canvas 转化下载

downloadIamge

new download().downloadIamge(link: string, fileName?: string)

Node 环境

获取本机 IP

systemOs.IP()

获取指定目录下面所有的文件名称以及路径

findSync('./package.json')

读取文件内容

readFileBase64Sync(path,coding)
string 要读的地址
path 编码类型 空字符串默认为 base64 可以指定其他字符
// 示例
readFileBase64Sync('../package.json', 'utf-8').then((res) => {
  console.log(res);
}).catch(err => {
  console.log('err', err);
})

写入文件

writeBase64({
  type: '',
  savePaht: 'F:\\Flutter',
  file: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAAASAAAAEgARslrPgAAAyNJREFUSMfllF1Ik1Ecxs+Z76JIyuaaWxF0IVE3ISTWRR9kpi6x2owyLAUlk2gh6iZEqXNmuczWYJSWBVmRAz/XdKjpt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yMS0xMS0xMlQxNTo0NzozMSswODowMOcD8ZYAAABLdEVYdHN2ZzpiYXNlLXVyaQBmaWxlOi8vL2hvbWUvYWRtaW4vaWNvbi1mb250L3RtcC9pY29uX3JvOHF3b2g0YnhhL3lvdXhpYW5nLnN2Zz5oXGYAAAAASUVORK5CYII='
}).then((res) => {
  console.log(join(__dirname), join(__filename), res);
}).catch(err => {
  console.log('err', err);
})

提取身份证信息

ChinaIdUserinfo.getProvinceAndCity('身份证号')

Promise 拒绝处理收集方法

EventPollingPromiseError((promise, reason, poccibyUnhandledRejection)=>{},30000)

字符串互转 Base64

decode.setDecode({ StatusCode: 1000, msg: "token失效" }) //  转base64
decode.getDecode(str) // base64字符还原

// "exports": { // ".": { // "import": "./dist/index.js", // "require": "./dist/index.js" // }, // "./package.json": "./package.json", // "import": "./index.ts", // "require": "./dist/index.js" // },