This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 扁平化数组 | |
// const a = [1, [2, [3,4]]]; flaten(a) | |
const flaten = arr => | |
arr.reduce( | |
(acc, cur) => Array.isArray(cur)?acc.concat(...fl(cur)):acc.concat(cur) | |
,[]) | |
// 判断数组中某个值出现的次数 | |
function countOccurrences(arr, value) { | |
return arr.reduce((a, v) => (v === value ? a + 1 : a + 0), 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useEffect } from "react"; | |
/** | |
* 根据 kw 过滤 list 的数据。用于纯前端数据搜索 | |
* initList: 没筛选时的初始列表 | |
* kw: 关键字, | |
* list: 返回的结果列表 | |
* keys: list 的 item 中用于和 kw 匹配的key | |
*/ | |
function useSearchFilter(keys, _initlist) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text-ellipsis { | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const idUq = id => item => item.id !== id; | |
export const idEq = id => item => item.id === id; | |
export const getId = item => item.id; | |
export const callFn = (fn, ...params) => { | |
if (typeof fn === 'function') { | |
return fn.apply(null, params) | |
} | |
} | |
export const a2z = (isUpper = false) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check list or object is null or empty | |
const isEmpty = obj = !obj || Object.keys(obj).length === 0; | |
export const isEmptyList = list => !list || list.length === 0; | |
export const isSameArray = (a1, a2) => { | |
if ( isEmptyList(a1) && isEmptyList(a2)) return true; | |
if (isEmptyList(a1) && !isEmptyList(a2)) return false; | |
if (!isEmptyList(a1) && isEmptyList(a2)) return false; | |
if (a1.length !== a2.length) return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function formatTime(_date, fm = 'YY.MM.DD hh:mm:ss') { | |
let d | |
if (Object.prototype.toString.call(_date).toLocaleLowerCase() === '[object date]') { | |
d = _date | |
} else { | |
d = new Date(_date) | |
} | |
let year = d.getFullYear() | |
let month = d.getMonth() + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = "<p></p>" | |
/<[^>]+>/i.test(str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const params = (function() { | |
const array = location.search.substr(1).split('&') | |
const obj = {} | |
array.forEach(item => { | |
const a = item.split('=') | |
const k = a[0] | |
const v = a[1] | |
obj[k] = v | |
}) | |
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onscroll = function() { | |
const documentEle = document.documentElement; | |
const offset = documentEle.scrollTop + window.innerHeight; | |
const height = documentEle.scrollHeight; | |
if (offset === height) { | |
console.log('At the bottom'); | |
} | |
} |