Skip to content

Instantly share code, notes, and snippets.

const isPrimitiveTypeOrFunction = (input) =>
typeof input !== 'object' || typeof input === 'function' || input === null;
function getType(input) {
const lowerCaseTheFirstLetter = (str) => str[0].toLowerCase() + str.slice(1);
const type = typeof input;
if (type !== 'object') return type;
return lowerCaseTheFirstLetter(
Object.prototype.toString.call(input).replace(/^\[object (\S+)\]$/, '$1'),
input = [
['google.com', '20'],
['mail.google.com', '10'],
['zhenghao.mail.google.com', '10'],
]
output = { 'google.com': 40,
'mail.google.com': 20,
'zhenghao.mail.google.com': 10 }
// <body>
// <div>
// <span>
// bar1
// bar2
// </span>
// </div>
// <div>
// baz
// </div>
@zhenghaohe
zhenghaohe / .ts
Created March 15, 2021 05:02
useRequest
type Status = "pending" | "resolved" | "rejected";
type State<R, E = unknown> = {
status: Status;
data: null | R;
error: null | E;
};
type Action<R, E = unknown> =
@zhenghaohe
zhenghaohe / .ts
Created January 24, 2021 01:39
useAsync.ts
type Status = "pending" | "resolved" | "rejected";
type State<R, E = unknown> = {
status: Status;
data: null | R;
error: null | E;
};
type Action<R, E = unknown> =
@zhenghaohe
zhenghaohe / useAsync.ts
Last active August 25, 2023 04:43
useAsync.ts
type Status = "pending" | "resolved" | "rejected";
type State<R, E = unknown> = {
status: Status;
data: null | R;
error: null | E;
};
type Action<R, E = unknown> =