feat(lib-core): biblioteca atomica @pulse-libs/core v1.0.0-beta.1

Esta commit conteudo a estrutura atomica completa:

- types:     Result<T,E>, AsyncState<T>, Paginated<T>, SortConfig<T>
- utils:     date, str, num, cn, debounce, throttle, storage, arr, obj
- validators: Zod schemas — email, password, uuid, url, phone, CPF/CNPJ, sanitizedStr, safeParse
- hooks:     useToggle, useAsync, useDebounce, useLocalStorage, useMedia, useInterval, useOnClickOutside, useClipboard, useFetch
- components: Button, Input, Alert, Card, Spinner (atomic design pattern)
- build:     tsup v8 ESM+CJS + DTS + sourcemaps — 0 erros
- tests:     57 testes 100% usuarios
- docker:    multi-stage Dockerfile (node 20-alpine)
- config:    vitest, tsup, tsconfig strict, .npmignore

Filosofia atomica:/utils ← /types ← /validators ← /hooks ← /components
Build: npm run build | Test: npm test | Publish: npm publish

🤖 Generated with Pulse (openclaw + nova-self-improver)
This commit is contained in:
pulse-agent
2026-05-19 21:43:03 -03:00
parent ae39e45460
commit bbdb68a6de
7030 changed files with 2040595 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
/**
* @pulse-libs/utils — Funções puras, zero dependências
* Usáveis em React, Vue, Node, browser
*/
declare const date: {
now: () => string;
format: (d: Date | string | number, fmt?: string) => string;
isToday: (d: Date | string) => boolean;
daysBetween: (a: Date, b: Date) => number;
};
declare const str: {
capitalize: (s: string) => string;
truncate: (s: string, max: number, suffix?: string) => string;
camelCase: (s: string) => string;
kebabCase: (s: string) => string;
slugify: (s: string) => string;
removeAccents: (s: string) => string;
maskEmail: (email: string) => string;
};
declare const num: {
clamp: (value: number, min: number, max: number) => number;
rand: (min: number, max: number) => number;
format: (n: number) => string;
percent: (part: number, total: number, decimals?: number) => number;
};
type ClassValue = string | boolean | null | undefined | Array<ClassValue>;
declare function cn(...inputs: ClassValue[]): string;
declare function debounce<T extends (...args: Parameters<T>) => void>(fn: T, ms: number): (...args: Parameters<T>) => void;
declare function throttle<T extends (...args: Parameters<T>) => void>(fn: T, ms: number): (...args: Parameters<T>) => void;
declare const storage: {
get: <T>(key: string, fallback: T) => T;
set: <T>(key: string, value: T) => void;
remove: (key: string) => void;
clear: (prefix?: string) => void;
};
declare const arr: {
unique: <T>(items: T[], key?: keyof T) => T[];
chunk: <T>(items: T[], size: number) => T[][];
shuffle: <T>(items: T[]) => T[];
};
declare const obj: {
pick: <T extends object, K extends keyof T>(o: T, keys: K[]) => Pick<T, K>;
omit: <T extends object, K extends keyof T>(o: T, keys: K[]) => Omit<T, K>;
isEmpty: (o: object | null | undefined) => boolean;
};
export { arr, cn, date, debounce, num, obj, storage, str, throttle };
+47
View File
@@ -0,0 +1,47 @@
/**
* @pulse-libs/utils — Funções puras, zero dependências
* Usáveis em React, Vue, Node, browser
*/
declare const date: {
now: () => string;
format: (d: Date | string | number, fmt?: string) => string;
isToday: (d: Date | string) => boolean;
daysBetween: (a: Date, b: Date) => number;
};
declare const str: {
capitalize: (s: string) => string;
truncate: (s: string, max: number, suffix?: string) => string;
camelCase: (s: string) => string;
kebabCase: (s: string) => string;
slugify: (s: string) => string;
removeAccents: (s: string) => string;
maskEmail: (email: string) => string;
};
declare const num: {
clamp: (value: number, min: number, max: number) => number;
rand: (min: number, max: number) => number;
format: (n: number) => string;
percent: (part: number, total: number, decimals?: number) => number;
};
type ClassValue = string | boolean | null | undefined | Array<ClassValue>;
declare function cn(...inputs: ClassValue[]): string;
declare function debounce<T extends (...args: Parameters<T>) => void>(fn: T, ms: number): (...args: Parameters<T>) => void;
declare function throttle<T extends (...args: Parameters<T>) => void>(fn: T, ms: number): (...args: Parameters<T>) => void;
declare const storage: {
get: <T>(key: string, fallback: T) => T;
set: <T>(key: string, value: T) => void;
remove: (key: string) => void;
clear: (prefix?: string) => void;
};
declare const arr: {
unique: <T>(items: T[], key?: keyof T) => T[];
chunk: <T>(items: T[], size: number) => T[][];
shuffle: <T>(items: T[]) => T[];
};
declare const obj: {
pick: <T extends object, K extends keyof T>(o: T, keys: K[]) => Pick<T, K>;
omit: <T extends object, K extends keyof T>(o: T, keys: K[]) => Omit<T, K>;
isEmpty: (o: object | null | undefined) => boolean;
};
export { arr, cn, date, debounce, num, obj, storage, str, throttle };
+150
View File
@@ -0,0 +1,150 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/index.ts
var utils_exports = {};
__export(utils_exports, {
arr: () => arr,
cn: () => cn,
date: () => date,
debounce: () => debounce,
num: () => num,
obj: () => obj,
storage: () => storage,
str: () => str,
throttle: () => throttle
});
module.exports = __toCommonJS(utils_exports);
var date = {
now: () => (/* @__PURE__ */ new Date()).toISOString(),
format: (d, fmt = "YYYY-MM-DD HH:mm") => {
const date2 = typeof d === "number" ? new Date(d) : new Date(d);
const map = {
YYYY: String(date2.getFullYear()),
MM: String(date2.getMonth() + 1).padStart(2, "0"),
DD: String(date2.getDate()).padStart(2, "0"),
HH: String(date2.getHours()).padStart(2, "0"),
mm: String(date2.getMinutes()).padStart(2, "0"),
ss: String(date2.getSeconds()).padStart(2, "0")
};
return fmt.replace(/YYYY|MM|DD|HH|mm|ss/g, (m) => map[m]);
},
isToday: (d) => {
const date2 = new Date(d);
const today = /* @__PURE__ */ new Date();
return date2.toDateString() === today.toDateString();
},
daysBetween: (a, b) => Math.ceil((b.getTime() - a.getTime()) / 864e5)
};
var str = {
capitalize: (s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase(),
truncate: (s, max, suffix = "\u2026") => s.length <= max ? s : s.slice(0, max).trimEnd() + suffix,
camelCase: (s) => s.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : ""),
kebabCase: (s) => s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
slugify: (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""),
removeAccents: (s) => s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""),
maskEmail: (email) => {
const [user, domain] = email.split("@");
return user.length <= 2 ? `${user[0]}*@${domain}` : `${user[0]}${"*".repeat(user.length - 2)}${user.at(-1)}@${domain}`;
}
};
var num = {
clamp: (value, min, max) => Math.min(Math.max(value, min), max),
rand: (min, max) => Math.floor(Math.random() * (max - min + 1)) + min,
format: (n) => n.toLocaleString("pt-BR"),
percent: (part, total, decimals = 1) => {
if (total === 0) return 0;
return parseFloat((part / total * 100).toFixed(decimals));
}
};
var CLEAN_CLASSES_REGEX = /\s+/g;
function cn(...inputs) {
return inputs.flat(2).filter(Boolean).join(" ").replace(CLEAN_CLASSES_REGEX, " ").trim();
}
function debounce(fn, ms) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), ms);
};
}
function throttle(fn, ms) {
let last = 0;
return (...args) => {
const now = Date.now();
if (now - last >= ms) {
last = now;
fn(...args);
}
};
}
var storage = {
get: (key, fallback) => {
try {
const v = typeof localStorage !== "undefined" ? localStorage.getItem(key) : null;
return v ? JSON.parse(v) : fallback;
} catch {
return fallback;
}
},
set: (key, value) => {
localStorage.setItem(key, JSON.stringify(value));
},
remove: (key) => {
try {
localStorage.removeItem(key);
} catch {
}
},
clear: (prefix) => {
if (prefix) Object.keys(localStorage).filter((k) => k.startsWith(prefix)).forEach((k) => localStorage.removeItem(k));
else localStorage.clear();
}
};
var arr = {
unique: (items, key) => {
if (!key) return [...new Set(items)];
return items.filter((v, i, a) => a.findIndex((item) => item[key] === v[key]) === i);
},
chunk: (items, size) => {
return Array.from({ length: Math.ceil(items.length / size) }, (_, i) => items.slice(i * size, i * size + size));
},
shuffle: (items) => [...items].sort(() => Math.random() - 0.5)
};
var obj = {
pick: (o, keys) => keys.reduce((r, k) => {
if (k in o) r[k] = o[k];
return r;
}, {}),
omit: (o, keys) => Object.fromEntries(Object.entries(o).filter(([k]) => !keys.includes(k))),
isEmpty: (o) => o == null || Object.keys(o).length === 0
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
arr,
cn,
date,
debounce,
num,
obj,
storage,
str,
throttle
});
//# sourceMappingURL=index.js.map
File diff suppressed because one or more lines are too long
+23
View File
@@ -0,0 +1,23 @@
import {
arr,
cn,
date,
debounce,
num,
obj,
storage,
str,
throttle
} from "../chunk-RL4ANBQD.mjs";
export {
arr,
cn,
date,
debounce,
num,
obj,
storage,
str,
throttle
};
//# sourceMappingURL=index.mjs.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}