@rainersoft/utils 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,28 +1,29 @@
1
1
  import { L as Locale } from './types-tUMATEGI.js';
2
2
  export { C as CURRENCY_MAP, D as DEFAULT_LOCALE, a as LocaleConfig } from './types-tUMATEGI.js';
3
- export { textToSlug } from './string/index.js';
4
- export { formatDate, formatDateTime, formatRelativeDate, isValidDate, toISOString } from './date/index.js';
3
+ import { d as dateModule } from './index-BA11MtKk.js';
4
+ export { f as formatDate, a as formatDateTime, b as formatRelativeDate, i as isValidDate, t as toISOString } from './index-BA11MtKk.js';
5
+ import { s as statusModule } from './index-BfZE8XjJ.js';
6
+ export { G as GenericStatus, g as getStatusColor, a as getStatusVariant, b as translatePostStatus, t as translateStatus } from './index-BfZE8XjJ.js';
7
+ import { a as authModule } from './index-DeZ9ZulO.js';
8
+ export { b as getRefreshToken, g as getToken, d as getTokens, h as hasToken, r as removeToken, c as setRefreshToken, s as setToken, e as setTokens } from './index-DeZ9ZulO.js';
9
+ export { SearchOptions, fuzzySearch, searchContent, searchWithScore } from './search/index.js';
10
+ export { formatCNPJ, formatCPF, formatPhone, getInitials, isCNPJ, isCPF, textToSlug, truncate } from './string/index.js';
5
11
  export { formatCurrency } from './number/index.js';
6
- export { GenericStatus, getStatusColor, getStatusVariant, translatePostStatus, translateStatus } from './status/index.js';
7
12
 
8
- declare function extractInitials(name: string | null | undefined, maxChars?: number): string;
9
- declare function generateAvatarUrl(name: string, size?: number, backgroundColor?: string, textColor?: string): string;
10
- declare function isValidAvatarUrl(url: string): boolean;
11
- declare function getAvatarColorFromName(name: string): string;
12
- declare function generateDynamicAvatarUrl(name: string, size?: number): string;
13
- declare function generateUniqueId(text: string, prefix?: string, suffix?: string): string;
14
- declare function truncateText(text: string, maxLength: number, suffix?: string): string;
15
- declare function capitalize(text: string, options?: {
16
- firstWordOnly?: boolean;
17
- lowerRest?: boolean;
18
- }): string;
19
- declare function cleanText(text: string, allowSpaces?: boolean): string;
20
- declare function countWords(text: string): number;
21
- declare function isEmpty(text: string | null | undefined): boolean;
22
- declare function normalizeSpaces(text: string, options?: {
23
- newlines?: boolean;
24
- }): string;
25
- declare function calculateReadingTime(content: string | Record<string, any>, wordsPerMinute?: number): number;
13
+ declare function hexToRgb(hex: string): {
14
+ r: number;
15
+ g: number;
16
+ b: number;
17
+ };
18
+ declare function validateContrast(foreground: string, background: string, options?: {
19
+ requireAAA?: boolean;
20
+ largeText?: boolean;
21
+ }): {
22
+ valid: boolean;
23
+ level: string;
24
+ contrast: number;
25
+ message: string;
26
+ };
26
27
 
27
28
  interface ValidationResult {
28
29
  isValid: boolean;
@@ -57,6 +58,47 @@ declare function validateMessage(message: string, options?: {
57
58
  maxLength?: number;
58
59
  }, locale?: Locale): ValidationResult;
59
60
 
61
+ interface TiptapNode {
62
+ type: string;
63
+ text?: string;
64
+ content?: TiptapNode[];
65
+ attrs?: Record<string, any>;
66
+ }
67
+ interface TiptapJSON {
68
+ type: 'doc';
69
+ content: TiptapNode[];
70
+ }
71
+ interface ContentStats {
72
+ wordCount: number;
73
+ characterCount: number;
74
+ readingTime: number;
75
+ }
76
+ declare function extractTextFromTiptap(content: TiptapJSON): string;
77
+ declare function generateExcerpt(content: TiptapJSON, maxLength?: number): string;
78
+ declare function createEmptyTiptapContent(): TiptapJSON;
79
+ declare function isContentEmpty(content: TiptapJSON): boolean;
80
+ declare function countCharacters(content: TiptapJSON): number;
81
+ declare function getReadingTime(content: TiptapJSON, wordsPerMinute?: number): number;
82
+ declare function getContentStats(content: TiptapJSON): ContentStats;
83
+ declare function containsText(content: TiptapJSON, searchText: string): boolean;
84
+ declare function replaceText(content: TiptapJSON, searchText: string, replaceText: string): TiptapJSON;
85
+
86
+ declare function rgbToHex(r: number, g: number, b: number): string;
87
+ declare function hexToHsl(hex: string): {
88
+ h: number;
89
+ s: number;
90
+ l: number;
91
+ };
92
+ declare function hslToHex(h: number, s: number, l: number): string;
93
+ declare function adjustBrightness(hex: string, amount: number): string;
94
+ declare function adjustSaturation(hex: string, amount: number): string;
95
+ declare function adjustHue(hex: string, degrees: number): string;
96
+ declare function lighten(hex: string, amount: number): string;
97
+ declare function darken(hex: string, amount: number): string;
98
+ declare function hexToRgba(hex: string, alpha: number): string;
99
+ declare function getComplementary(hex: string): string;
100
+ declare function getAnalogousPalette(hex: string, count?: number): string[];
101
+
60
102
  declare function prefersReducedMotion(): boolean;
61
103
  declare function onReducedMotionChange(callback: (prefersReduced: boolean) => void): () => void;
62
104
  declare function scrollToPosition(x?: number, y?: number, options?: {
@@ -81,6 +123,72 @@ declare function onDarkModeChange(callback: (isDark: boolean) => void): () => vo
81
123
  declare function copyToClipboard(text: string): Promise<boolean>;
82
124
  declare function downloadFile(blob: Blob, filename: string): void;
83
125
 
126
+ interface UserProfile {
127
+ id: string;
128
+ nickname: string;
129
+ email?: string;
130
+ emailVerified?: boolean;
131
+ role?: UserRole;
132
+ avatar?: string;
133
+ createdAt?: string;
134
+ updatedAt?: string;
135
+ lastLoginAt?: string;
136
+ }
137
+ declare enum UserRole {
138
+ ADMIN = "admin",
139
+ MODERATOR = "moderator",
140
+ USER = "user",
141
+ GUEST = "guest"
142
+ }
143
+ interface LoginCredentials {
144
+ email: string;
145
+ password: string;
146
+ rememberMe?: boolean;
147
+ }
148
+ interface RegisterData {
149
+ nickname: string;
150
+ email: string;
151
+ password: string;
152
+ confirmPassword: string;
153
+ role?: UserRole;
154
+ }
155
+ interface LogoutOptions {
156
+ invalidateAllSessions?: boolean;
157
+ redirectPath?: string;
158
+ }
159
+ interface AuthResult {
160
+ success: boolean;
161
+ user?: UserProfile;
162
+ token?: string;
163
+ refreshToken?: string;
164
+ error?: string;
165
+ }
166
+ interface UseAuthConfig {
167
+ autoRefresh?: boolean;
168
+ refreshInterval?: number;
169
+ tokenStorageKey?: string;
170
+ userStorageKey?: string;
171
+ apiEndpoint?: string;
172
+ onAuthChange?: (user: UserProfile | null) => void;
173
+ onError?: (error: string) => void;
174
+ }
175
+ declare function useAuth(config?: Partial<UseAuthConfig>): {
176
+ user: UserProfile | null;
177
+ loading: boolean;
178
+ error: string | null;
179
+ isAuthenticated: boolean;
180
+ login: (credentials: LoginCredentials) => Promise<AuthResult>;
181
+ logout: (options?: LogoutOptions) => Promise<void>;
182
+ register: (userData: RegisterData) => Promise<AuthResult>;
183
+ updateProfile: (data: Partial<UserProfile>) => Promise<AuthResult>;
184
+ refreshToken: () => Promise<AuthResult>;
185
+ resetError: () => void;
186
+ };
187
+ declare function useIsAuthenticated(): boolean;
188
+ declare function useCurrentUser(): UserProfile | null;
189
+ declare function useHasRole(role: UserRole): boolean;
190
+ declare function useIsAdmin(): boolean;
191
+
84
192
  declare function formatNumber$1(num: number): string;
85
193
  declare function calculateChange(current: number, previous: number): number;
86
194
  declare function formatPercentage(value: number, options?: {
@@ -95,32 +203,6 @@ declare function findMinMax<T extends Record<string, any>>(data: T[], field: key
95
203
  max: number;
96
204
  };
97
205
 
98
- declare const getToken: () => string | null;
99
- declare const setToken: (token: string) => void;
100
- declare const getRefreshToken: () => string | null;
101
- declare const setRefreshToken: (refreshToken: string) => void;
102
- declare const removeToken: () => void;
103
- declare const hasToken: () => boolean;
104
- declare const getTokens: () => {
105
- accessToken: string | null;
106
- refreshToken: string | null;
107
- };
108
- declare const setTokens: ({ accessToken, refreshToken, }: {
109
- accessToken: string;
110
- refreshToken: string;
111
- }) => void;
112
-
113
- interface SearchOptions {
114
- fields?: string[];
115
- caseSensitive?: boolean;
116
- exactMatch?: boolean;
117
- }
118
- declare function searchContent<T extends Record<string, any>>(query: string, content: T[], options?: SearchOptions): T[];
119
- declare function searchWithScore<T extends Record<string, any>>(query: string, content: T[], options?: SearchOptions): T[];
120
- declare function fuzzySearch<T extends Record<string, any>>(query: string, content: T[], options?: SearchOptions & {
121
- threshold?: number;
122
- }): T[];
123
-
124
206
  declare function usePasswordStrength(password: string, options?: {
125
207
  minLength?: number;
126
208
  requireUppercase?: boolean;
@@ -174,6 +256,15 @@ declare function formatCurrency(value: number, options?: Intl.NumberFormatOption
174
256
  declare function formatNumber(value: number, decimals?: number): string;
175
257
  declare function formatCompact(value: number, decimals?: number): string;
176
258
  declare function translateStatus(status: string): string;
259
+ declare const _default: {
260
+ formatDate: typeof formatDate;
261
+ formatDateTime: typeof formatDateTime;
262
+ formatRelativeDate: typeof formatRelativeDate;
263
+ formatCurrency: typeof formatCurrency;
264
+ formatNumber: typeof formatNumber;
265
+ formatCompact: typeof formatCompact;
266
+ translateStatus: typeof translateStatus;
267
+ };
177
268
 
178
269
  declare const ptBr_formatCompact: typeof formatCompact;
179
270
  declare const ptBr_formatCurrency: typeof formatCurrency;
@@ -183,7 +274,48 @@ declare const ptBr_formatNumber: typeof formatNumber;
183
274
  declare const ptBr_formatRelativeDate: typeof formatRelativeDate;
184
275
  declare const ptBr_translateStatus: typeof translateStatus;
185
276
  declare namespace ptBr {
186
- export { ptBr_formatCompact as formatCompact, ptBr_formatCurrency as formatCurrency, ptBr_formatDate as formatDate, ptBr_formatDateTime as formatDateTime, ptBr_formatNumber as formatNumber, ptBr_formatRelativeDate as formatRelativeDate, ptBr_translateStatus as translateStatus };
277
+ export { _default as default, ptBr_formatCompact as formatCompact, ptBr_formatCurrency as formatCurrency, ptBr_formatDate as formatDate, ptBr_formatDateTime as formatDateTime, ptBr_formatNumber as formatNumber, ptBr_formatRelativeDate as formatRelativeDate, ptBr_translateStatus as translateStatus };
278
+ }
279
+
280
+ declare function extractInitials(name: string | null | undefined, maxChars?: number): string;
281
+ declare function generateAvatarUrl(name: string, size?: number, backgroundColor?: string, textColor?: string): string;
282
+ declare function isValidAvatarUrl(url: string): boolean;
283
+ declare function getAvatarColorFromName(name: string): string;
284
+ declare function generateDynamicAvatarUrl(name: string, size?: number): string;
285
+ declare function generateUniqueId(text: string, prefix?: string, suffix?: string): string;
286
+ declare function truncateText(text: string, maxLength: number, suffix?: string): string;
287
+ declare function capitalize(text: string, options?: {
288
+ firstWordOnly?: boolean;
289
+ lowerRest?: boolean;
290
+ }): string;
291
+ declare function cleanText(text: string, allowSpaces?: boolean): string;
292
+ declare function countWords(text: string): number;
293
+ declare function isEmpty(text: string | null | undefined): boolean;
294
+ declare function normalizeSpaces(text: string, options?: {
295
+ newlines?: boolean;
296
+ }): string;
297
+ declare function calculateReadingTime(content: string | Record<string, any>, wordsPerMinute?: number): number;
298
+
299
+ declare const textModule_calculateReadingTime: typeof calculateReadingTime;
300
+ declare const textModule_capitalize: typeof capitalize;
301
+ declare const textModule_cleanText: typeof cleanText;
302
+ declare const textModule_countWords: typeof countWords;
303
+ declare const textModule_extractInitials: typeof extractInitials;
304
+ declare const textModule_generateAvatarUrl: typeof generateAvatarUrl;
305
+ declare const textModule_generateDynamicAvatarUrl: typeof generateDynamicAvatarUrl;
306
+ declare const textModule_generateUniqueId: typeof generateUniqueId;
307
+ declare const textModule_getAvatarColorFromName: typeof getAvatarColorFromName;
308
+ declare const textModule_isEmpty: typeof isEmpty;
309
+ declare const textModule_isValidAvatarUrl: typeof isValidAvatarUrl;
310
+ declare const textModule_normalizeSpaces: typeof normalizeSpaces;
311
+ declare const textModule_truncateText: typeof truncateText;
312
+ declare namespace textModule {
313
+ export { textModule_calculateReadingTime as calculateReadingTime, textModule_capitalize as capitalize, textModule_cleanText as cleanText, textModule_countWords as countWords, textModule_extractInitials as extractInitials, textModule_generateAvatarUrl as generateAvatarUrl, textModule_generateDynamicAvatarUrl as generateDynamicAvatarUrl, textModule_generateUniqueId as generateUniqueId, textModule_getAvatarColorFromName as getAvatarColorFromName, textModule_isEmpty as isEmpty, textModule_isValidAvatarUrl as isValidAvatarUrl, textModule_normalizeSpaces as normalizeSpaces, textModule_truncateText as truncateText };
187
314
  }
188
315
 
189
- export { Locale, type SearchOptions, type ValidationResult, calculateChange, calculateMovingAverage, calculateReadingTime, capitalize, cleanText, copyToClipboard, countWords, downloadFile, extractInitials, findMinMax, formatNumber$1 as formatNumber, formatPercentage, fuzzySearch, generateAvatarUrl, generateDynamicAvatarUrl, generateMockChartData, generateUniqueId, getAvatarColorFromName, getElementPosition, getRefreshToken, getToken, getTokens, groupDataByPeriod, hasToken, isDarkMode, isElementVisible, isEmpty, isMobile, isValidAvatarUrl, normalizeSpaces, onDarkModeChange, onReducedMotionChange, prefersReducedMotion, ptBr as ptBR, removeToken, scrollToElement, scrollToPosition, scrollToTop, searchContent, searchWithScore, setRefreshToken, setToken, setTokens, smoothScrollTo, truncateText, usePasswordStrength, validateEmail, validateMessage, validatePassword, validatePhone, validateSlug, validateText, validateUrl, validateUsername };
316
+ declare const textProcessing: typeof textModule;
317
+ declare const datetime: typeof dateModule;
318
+ declare const authentication: typeof authModule;
319
+ declare const stateManagement: typeof statusModule;
320
+
321
+ export { type ContentStats, Locale, type TiptapJSON, type TiptapNode, type ValidationResult, adjustBrightness, adjustHue, adjustSaturation, authentication, calculateChange, calculateMovingAverage, calculateReadingTime, capitalize, cleanText, containsText, copyToClipboard, countCharacters, countWords, createEmptyTiptapContent, darken, datetime, downloadFile, extractInitials, extractTextFromTiptap, findMinMax, formatNumber$1 as formatNumber, formatPercentage, generateAvatarUrl, generateDynamicAvatarUrl, generateExcerpt, generateMockChartData, generateUniqueId, getAnalogousPalette, getAvatarColorFromName, getComplementary, getContentStats, getElementPosition, getReadingTime, groupDataByPeriod, hexToHsl, hexToRgb, hexToRgba, hslToHex, isContentEmpty, isDarkMode, isElementVisible, isEmpty, isMobile, isValidAvatarUrl, lighten, normalizeSpaces, onDarkModeChange, onReducedMotionChange, prefersReducedMotion, ptBr as ptBR, replaceText, rgbToHex, scrollToElement, scrollToPosition, scrollToTop, smoothScrollTo, stateManagement, textProcessing, truncateText, useAuth, useCurrentUser, useHasRole, useIsAdmin, useIsAuthenticated, usePasswordStrength, validateContrast, validateEmail, validateMessage, validatePassword, validatePhone, validateSlug, validateText, validateUrl, validateUsername };