Skip to content

Instantly share code, notes, and snippets.

@renzhezhilu
renzhezhilu / 文件离线or缓存到浏览器.js
Last active May 7, 2020 18:17
[Cache_files_to_browser]#Uint8Array_to_text #text_to_Blob
function fileSaveLocal(fileUrl = 'https://cdn.jsdelivr.net/npm/localforage@1.7.3/dist/localforage.min.js',
name = '未命名',
type = 'text/txt') {
let blobUrl = null
let isHave = localStorage.getItem(name)
function getData() {
let txtData = localStorage.getItem(name)
let u = new Uint8Array(JSON.parse(txtData))
let b = new Blob([u.buffer], {
// 获取图片的宽和高
function getImagesWidthHeight(url = "blob | base64 | url") {
return new Promise((ret) => {
let img = new Image()
img.src = url
img.onload = function() {
ret({
width: this.width,
height: this.height,
image: this
@renzhezhilu
renzhezhilu / downloadZip.js
Created October 14, 2019 14:11
[下载多个文件后打包成ZIP再下载] #数据处理
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>下载多个文件后打包成ZIP再下载</title>
</head>
<body>
@renzhezhilu
renzhezhilu / fetchStart.js
Last active March 1, 2020 08:57
[fetch浏览器] #请求
//https://developer.mozilla.org/zh-CN/docs/Web/API/Body
fetch(`https://xxxxxx`)
.then(x=>{
return x.json()
//x.text()
//x.blob()
//x.formData()
//x.arrayBuffer()
}).then(d=>{
@renzhezhilu
renzhezhilu / promiseStart.js
Last active October 14, 2019 13:25
[Promise起手] #Promise
function timeout(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms, 'done');
});
}
async function f (){
let d = await timeout(100)
console.log('100After...')
}
@renzhezhilu
renzhezhilu / findExactlyString.js
Created October 10, 2019 03:25
[提取图片array前缀] #压缩文件
//提取图片前缀
function findExactlyString(arr) {
if (arr.length <= 1) return {
leg: 0,
str: '',
diffArr: arr
}
let leg = 0
let arr00 = arr[0]
for (let i = 0; i < arr00.length; i++) {
@renzhezhilu
renzhezhilu / funDownload.js
Created October 10, 2019 03:14
[下载文件/bolb转文本文件] #数据转换
//下载文件
// funDownload(JSON.stringify(xxxx),'xxx.json')
function funDownload(content, filename) {
let eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
let blob = new Blob([content]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
@renzhezhilu
renzhezhilu / blobToBase64.js
Created October 10, 2019 02:45
[blob和base64互相转换]#浏览器全局对象 #数据转换
//blob转base64
function blobToDataURI(blob, callback) {
let reader = new FileReader();
reader.onload = function(e) {
callback(e.target.result);
}
reader.readAsDataURL(blob);
}
//base64转blob
function dataURItoBlob(dataURI) {
@renzhezhilu
renzhezhilu / npm模块.md
Last active September 13, 2019 11:13
[npm模块] #npm #node

Procfile