WishMeLz

生活其实很有趣

分类 JS 下的文章

随机渐变背景

<style> html, body { margin: 0; } body:after { content: 'click to update'; font-size: 0.8em; color: rgba(0, 0, 0, 0.3); position: fixed; width: 100%; bott...

ANSI 字体在前端展示 Jenkins日志

最近在做运维平台的开发,前端需要显示Jenkins的日志在前端,其中的ANSI字体就是如下示例。192.168.134.39:服务启动,端口检测,等待第3秒 192.168.134.39:服务启动,端口检测,等待第6秒 192.168.134.39:服务启动,端口检测,等待第9秒 192.168.134.39:服务启动,端口检测,等待第12秒 192.168.134.39:服务启动,端口检测,等待第15秒 192.168.134.39:服务启动,端口...

获取视频某一秒的截图

const handleGetVideoThumb = async function (url, options = {}) { if (typeof url !== "string") { console.error("URL must be a string"); return; } // 默认参数 const ...

SSE(Server-Sent Events)

服务端const express = require("express"); const cors = require("cors"); const app = express(); const port = 6548; app.use(cors()); app.get("/sse", (req, res) => { res.set({ "Content-Type": "text/event-stream", &quo...

金额大写

金额转换大写引用与:https://github.com/cnwhy/nzh/blob/master/lib/nzh.cn.jsfunction createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var utils = createCommonjsModule(function (module, exports) { var REG_NUMBER = /^([+-...

markdown 编辑器 md编辑器

腾讯开源的 markdown 编辑器 https://github.com/Tencent/cherry-markdown字节跳动开源的 markdown 编辑器 https://github.com/bytedance/bytemd

文件处理

1、base64转file对象let imageBase64 let blob = dataURLtoBlob(imageBase64) let file = blobToFile(blob, Date.now() + '.png') dataURLtoBlob(dataurl) { var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), ...

文字高亮

const regex = new RegExp(searchContent, "gi"); return text.replace(regex,'<span style="color:#286CFB;">$&</span>');

浏览器麦克风使用

<button type="button" id="start-btn">开始录音</button> <button type="button" id="stop-btn">停止录音</button> <button type="button" id="play-btn">播放录音</button>const startBtn = do...

非对称加密(node-rsa,jsencrypt)

公钥私钥生成随便找个在线生成的http://www.metools.info/code/c80.htmlORconst NodeRSA = require('node-rsa') const fs = require('fs') const newkey = new NodeRSA({ b: 512 }) newkey.setOptions({ encryptionScheme: 'pkcs1' }) let public_key = newkey.exportKey('pkcs8-public') //公钥 let private_key =...

Twitter_Snowflake(雪花算法)

import bigInt from 'big-integer'; // http://peterolson.github.io/BigInteger.js/ /** * Twitter_Snowflake(雪花算法) * * SnowFlake的结构如下(共64bits,每部分用-分开): * 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 * | ----------------------|--------...

decimal.js 加减乘除

import Decimal from 'decimal.js'; // 加法 function add(...nums: number[]): number { return nums.reduce((total, num) => new Decimal(total).plus(num), 0).toNumber(); } // 减法 function subtract(...nums: number[]): number { return nums.reduce((total, num) => new Decimal(t...

storage封装

/*** * title: storage.js * Author: wish * Email: - * Time: 2022/7/25 21:32 * last: 2022/7/25 21:54 * Desc: 对存储的简单封装 */ import CryptoJS from 'crypto-js'; // 十六位十六进制数作为密钥 const SECRET_KEY = CryptoJS.enc.Utf8.parse("3333e6e143439161"); // 十六位十六进制数作为密钥偏移量 const SECRET_IV...

数字千分位

num = 12345.45678 num.toLocaleString('en-US',{minimumFractionDigits:5}) minimumFractionDigits:保留小数几位

JS修改input的value触发change事件

var inp = document.querySelector('input'); var ev = new Event('input', { bubbles: true }); ev.simulated = true; inp.value = 'new value' inp.dispatchEvent(ev);

JS生成字母A-Z

var arr = []; for(var i = 65; i < 91; i++){ arr.push(String.fromCharCode(i)); } return arr;

多级目录将数据递归成树状

let data = [ { id: 1, name: "电器", parentid: 0 }, { id: 2, name: "日用品", parentid: 0 }, { id: 3, name: "车用品", parentid: 0 }, { id: 4, name: "电饭煲", parentid: 1 }, { id: 5, name: "毛巾", parentid: 2 }, { id: 6, name: "雨刷器", parentid: 3 }, { id: 7, nam...

时间API

苏宁: https://f.m.suning.com/api/ct.do or http://quan.suning.com/getSysTime.do { "api": "time", "code": "1", "currentTime": 1647506518039, "msg": "" } or { "sysTime2": "2022-03-17 16:46:39", "sysTime1": "20220317164639" } 淘宝: http://api.m.taoba...

JS计算两个日期相差天数

function Start(startDateString, endDateString) { var startDate = Date.parse(startDateString); var endDate = Date.parse(endDateString); if (startDate > endDate) { return 0; } if (startDate == endDate) { return -1; //相等 } var days = (endDate - startDate) / ...

微信机器人PC

https://github.com/cixingguangming55555/wechat-bot在PC端使用工具注入DLL,后台会启动一个WevSocket,实时发送消息.通过监听对呀的消息做处理