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
interface Options { | |
year?: "numeric" | "2-digit" | |
month?: "long" | "short" | |
day?: "numeric" | |
} | |
export default function formatDate(date: Date | string = ""): string { | |
const options: Options = { | |
year: "numeric", | |
month: "long", |
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
# If you come from bash you might have to change your $PATH. | |
# export PATH=$HOME/bin:/usr/local/bin:$PATH | |
# Path to your oh-my-zsh installation. | |
export ZSH="/Users/Mac/.oh-my-zsh" | |
# Set name of the theme to load --- if set to "random", it will | |
# load a random theme each time oh-my-zsh is loaded, in which case, | |
# to know which specific one was loaded, run: echo $RANDOM_THEME | |
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes |
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 chunk<T>(a: Array<T>, n: number): Array<Array<T>> { | |
if (n === 0) { | |
return [a]; | |
} | |
const chunks: Array<Array<T>> = []; | |
let i = 0; | |
while (i < a.length) { | |
chunks.push(a.slice(i, (i += n))); |
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
/** | |
* 首字母大写转换 | |
* @param {string} word | |
*/ | |
export const firstUpperCase = ([first, ...rest]) => | |
first.toUpperCase() + rest.join(''); |
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
function generateInstanceID() { | |
const a = "abcdefghijklmnopqrstuv"; | |
const l = a.length; | |
const t = Date.now(); | |
const r = [0, 0, 0].map(d => a[Math.floor(Math.random() * l)]).join(""); | |
return `${r}${t}`; | |
} |
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
// reference: https://stackoverflow.com/questions/4481485/changing-css-pseudo-element-styles-via-javascript/12207551#answer-8051488 | |
var addRule = (function (style) { | |
var sheet = document.head.appendChild(style).sheet; | |
return function (selector, css) { | |
var propText = typeof css === "string" ? css : Object.keys(css).map(function (p) { | |
return p + ":" + (p === "content" ? "'" + css[p] + "'" : css[p]); | |
}).join(";"); | |
sheet.insertRule(selector + "{" + propText + "}", sheet.cssRules.length); | |
}; |
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 copyToClip = (text) => { | |
const input = document.createElement('input') | |
input.setAttribute('value', text) | |
input.setAttribute('readonly', 'readonly') | |
document.body.appendChild(input) | |
input.select() | |
try { | |
document.execCommand('copy') | |
} catch() { | |
console.log('无法复制,请手动复制!') |
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
new IntersectionObserver( | |
([change]) => { | |
// 被覆盖就是 false,反之 true | |
console.log(change.isVisible) | |
}, | |
{ | |
threshold: [1.0], | |
delay: 1000, | |
trackVisibility: true | |
} |
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 measureTime = (cb, ...args) => { | |
const t0 = performance.now() | |
cb(...args) | |
const t1 = performance.now() | |
console.log(`Call to do something took ${t1 - t0} milliseconds.`) | |
} | |
measureTime(myFunction, params) |
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
class A { | |
p1() { | |
console.log('this is p1') | |
} | |
} | |
class B { | |
p2() { | |
console.log('this is p2') | |
} |
NewerOlder