@wp-001/fe-toolkit
v0.1.0
Published
A lightweight frontend utility toolkit with 100+ common helpers for Vue, React, Vite, Nuxt and TypeScript projects.
Maintainers
Readme
@wp-001/fe-toolkit
一个轻量级前端工具函数库,适合 Vue、React、Vite、Nuxt 和 TypeScript 项目使用。
当前版本内置 100+ 常用函数,覆盖类型判断、字符串、数字、数组、对象、URL、日期、树结构、异步函数、缓存、浏览器能力、ID 生成等常用业务场景。
安装
pnpm add @wp-001/fe-toolkit也可以使用 npm:
npm install @wp-001/fe-toolkit使用
import {
isEmpty,
debounce,
formatDate,
listToTree,
localCache,
camelCase,
formatMoney,
objectToQuery
} from '@wp-001/fe-toolkit';
console.log(isEmpty(''));
console.log(camelCase('hello-world'));
console.log(formatDate(new Date(), 'YYYY-MM-DD'));
console.log(formatMoney(123456.789, 2, '¥'));
console.log(objectToQuery({ page: 1, keyword: 'test' }));
const handleSearch = debounce(() => {
console.log('search');
}, 300);
localCache.set('token', '123456');
console.log(localCache.get('token'));
const tree = listToTree([
{ id: '1', parentId: null, name: '一级' },
{ id: '2', parentId: '1', name: '二级' }
]);模块能力
类型判断
getType,
isNull,
isUndefined,
isNil,
isString,
isNumber,
isBoolean,
isFunction,
isObject,
isPlainObject,
isArray,
isDate,
isRegExp,
isPromise,
isMap,
isSet,
isBlob,
isFile,
isEmpty,
isEqual字符串
capitalize,
uncapitalize,
camelCase,
pascalCase,
kebabCase,
snakeCase,
trim,
trimStart,
trimEnd,
removeSpaces,
truncate,
maskString,
maskPhone,
maskEmail,
randomString,
escapeHtml,
unescapeHtml,
stripHtml,
startsWith,
endsWith,
contains,
countText,
repeatString,
padLeft,
padRight数字与金额
toNumber,
clamp,
randomInt,
randomFloat,
round,
floorTo,
ceilTo,
sum,
average,
min,
max,
formatNumber,
formatMoney,
toPercent,
bytesToSize,
fileSizeToBytes,
isBetween数组
unique,
uniqueBy,
chunk,
flatten,
compact,
groupBy,
sortBy,
orderBy,
removeItem,
moveItem,
range,
sample,
shuffle,
intersection,
difference,
union,
first,
last,
partition,
countBy对象
deepClone,
deepMerge,
pick,
omit,
getValue,
setValue,
hasValue,
removeValue,
renameKey,
mapValues,
filterObject,
clearEmpty,
objectToArray,
arrayToObject,
freezeDeep,
safeJsonParse,
safeJsonStringifyURL
objectToQuery,
queryToObject,
getQueryParam,
setQueryParam,
removeQueryParam,
joinUrl,
normalizeUrl,
parseUrl,
isAbsoluteUrl,
addUrlPrefix日期时间
formatDate,
addDays,
addMonths,
addYears,
startOfDay,
endOfDay,
diffDays,
isToday,
isYesterday,
isTomorrow,
getWeekday,
getMonthDays,
formatDuration,
timeAgo,
isValidDate,
compareDate树结构
listToTree,
treeToList,
findTreeNode,
mapTree,
filterTree,
getTreePath,
eachTree,
removeTreeNode函数与异步
debounce,
throttle,
sleep,
once,
retry,
waitUntil,
noop,
createQueue,
runTasksLimit,
memoize缓存
createCache,
localCache,
sessionCache,
getStorageItem,
setStorageItem浏览器
copyText,
downloadBlob,
downloadText,
downloadJson,
downloadUrl,
getCookie,
setCookie,
removeCookie,
getViewportSize,
scrollToTop,
isBrowserID
createId,
uuid,
nanoid开发
pnpm install
pnpm test
pnpm typecheck
pnpm build
pnpm pack:check发布
当前包名已经设置为:
{
"name": "@wp-001/fe-toolkit",
"version": "0.1.0"
}发布前建议先执行:
pnpm test
pnpm typecheck
pnpm build
pnpm pack:check然后发布:
pnpm publish如果需要手动指定公开发布:
pnpm publish --access public版本升级
修 bug:
pnpm version patch
pnpm publish新增功能:
pnpm version minor
pnpm publish破坏性升级:
pnpm version major
pnpm publish