@excofy/utils 1.0.3 → 1.0.5

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.cjs CHANGED
@@ -33,7 +33,8 @@ __export(index_exports, {
33
33
  createValidator: () => createValidator,
34
34
  htmlEntityDecode: () => htmlEntityDecode,
35
35
  numberUtils: () => number_exports,
36
- slugUtils: () => slug_exports
36
+ slugUtils: () => slug_exports,
37
+ stringUtils: () => stringUtils
37
38
  });
38
39
  module.exports = __toCommonJS(index_exports);
39
40
 
@@ -358,6 +359,16 @@ function createValidator() {
358
359
  current.pushError(message);
359
360
  return validator;
360
361
  },
362
+ test(validateFn, message) {
363
+ if (shouldSkipValidation()) return validator;
364
+ const isValid = validateFn(current.value, {
365
+ field: String(current.field)
366
+ });
367
+ if (!isValid) {
368
+ current.pushError(message);
369
+ }
370
+ return validator;
371
+ },
361
372
  videoUrl: {
362
373
  youtube(message) {
363
374
  if (shouldSkipValidation()) {
@@ -480,6 +491,11 @@ function createValidator() {
480
491
  };
481
492
  }
482
493
 
494
+ // src/helpers/string.ts
495
+ var stringUtils = {
496
+ removeFileExtension: (fileName) => fileName.replace(/\.[^/.]+$/, "")
497
+ };
498
+
483
499
  // src/helpers/slug.ts
484
500
  var slug_exports = {};
485
501
  __export(slug_exports, {
@@ -522,5 +538,6 @@ var toDecimal = (value) => {
522
538
  createValidator,
523
539
  htmlEntityDecode,
524
540
  numberUtils,
525
- slugUtils
541
+ slugUtils,
542
+ stringUtils
526
543
  });
package/dist/index.d.cts CHANGED
@@ -58,6 +58,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
58
58
  url(message: string): /*elided*/ any;
59
59
  uuid(message: string): /*elided*/ any;
60
60
  oneOf: (types: string[], message: string) => /*elided*/ any;
61
+ test(validateFn: (value: TInputValue, context: {
62
+ field: string;
63
+ }) => boolean, message: string): /*elided*/ any;
61
64
  videoUrl: {
62
65
  youtube(message: string): /*elided*/ any;
63
66
  };
@@ -82,6 +85,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
82
85
  url(message: string): /*elided*/ any;
83
86
  uuid(message: string): /*elided*/ any;
84
87
  oneOf: (types: string[], message: string) => /*elided*/ any;
88
+ test(validateFn: (value: TInputValue, context: {
89
+ field: string;
90
+ }) => boolean, message: string): /*elided*/ any;
85
91
  videoUrl: {
86
92
  youtube(message: string): /*elided*/ any;
87
93
  };
@@ -93,6 +99,10 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
93
99
  };
94
100
  };
95
101
 
102
+ declare const stringUtils: {
103
+ removeFileExtension: (fileName: string) => string;
104
+ };
105
+
96
106
  /**
97
107
  * Generates a unique slug by appending a numeric suffix to the base slug if necessary.
98
108
  *
@@ -155,4 +165,4 @@ declare namespace number {
155
165
  export { number_toCents as toCents, number_toDecimal as toDecimal };
156
166
  }
157
167
 
158
- export { createValidator, htmlEntityDecode, number as numberUtils, slug as slugUtils };
168
+ export { createValidator, htmlEntityDecode, number as numberUtils, slug as slugUtils, stringUtils };
package/dist/index.d.ts CHANGED
@@ -58,6 +58,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
58
58
  url(message: string): /*elided*/ any;
59
59
  uuid(message: string): /*elided*/ any;
60
60
  oneOf: (types: string[], message: string) => /*elided*/ any;
61
+ test(validateFn: (value: TInputValue, context: {
62
+ field: string;
63
+ }) => boolean, message: string): /*elided*/ any;
61
64
  videoUrl: {
62
65
  youtube(message: string): /*elided*/ any;
63
66
  };
@@ -82,6 +85,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
82
85
  url(message: string): /*elided*/ any;
83
86
  uuid(message: string): /*elided*/ any;
84
87
  oneOf: (types: string[], message: string) => /*elided*/ any;
88
+ test(validateFn: (value: TInputValue, context: {
89
+ field: string;
90
+ }) => boolean, message: string): /*elided*/ any;
85
91
  videoUrl: {
86
92
  youtube(message: string): /*elided*/ any;
87
93
  };
@@ -93,6 +99,10 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
93
99
  };
94
100
  };
95
101
 
102
+ declare const stringUtils: {
103
+ removeFileExtension: (fileName: string) => string;
104
+ };
105
+
96
106
  /**
97
107
  * Generates a unique slug by appending a numeric suffix to the base slug if necessary.
98
108
  *
@@ -155,4 +165,4 @@ declare namespace number {
155
165
  export { number_toCents as toCents, number_toDecimal as toDecimal };
156
166
  }
157
167
 
158
- export { createValidator, htmlEntityDecode, number as numberUtils, slug as slugUtils };
168
+ export { createValidator, htmlEntityDecode, number as numberUtils, slug as slugUtils, stringUtils };
package/dist/index.js CHANGED
@@ -325,6 +325,16 @@ function createValidator() {
325
325
  current.pushError(message);
326
326
  return validator;
327
327
  },
328
+ test(validateFn, message) {
329
+ if (shouldSkipValidation()) return validator;
330
+ const isValid = validateFn(current.value, {
331
+ field: String(current.field)
332
+ });
333
+ if (!isValid) {
334
+ current.pushError(message);
335
+ }
336
+ return validator;
337
+ },
328
338
  videoUrl: {
329
339
  youtube(message) {
330
340
  if (shouldSkipValidation()) {
@@ -447,6 +457,11 @@ function createValidator() {
447
457
  };
448
458
  }
449
459
 
460
+ // src/helpers/string.ts
461
+ var stringUtils = {
462
+ removeFileExtension: (fileName) => fileName.replace(/\.[^/.]+$/, "")
463
+ };
464
+
450
465
  // src/helpers/slug.ts
451
466
  var slug_exports = {};
452
467
  __export(slug_exports, {
@@ -488,5 +503,6 @@ export {
488
503
  createValidator,
489
504
  htmlEntityDecode,
490
505
  number_exports as numberUtils,
491
- slug_exports as slugUtils
506
+ slug_exports as slugUtils,
507
+ stringUtils
492
508
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excofy/utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Biblioteca de utilitários para o Excofy",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,4 @@
1
+ export const stringUtils = {
2
+ removeFileExtension: (fileName: string): string =>
3
+ fileName.replace(/\.[^/.]+$/, ''),
4
+ };
@@ -337,6 +337,23 @@ export function createValidator<
337
337
  return validator;
338
338
  },
339
339
 
340
+ test(
341
+ validateFn: (value: TInputValue, context: { field: string }) => boolean,
342
+ message: string
343
+ ) {
344
+ if (shouldSkipValidation()) return validator;
345
+
346
+ const isValid = validateFn(current.value, {
347
+ field: String(current.field),
348
+ });
349
+
350
+ if (!isValid) {
351
+ current.pushError(message);
352
+ }
353
+
354
+ return validator;
355
+ },
356
+
340
357
  videoUrl: {
341
358
  youtube(message: string) {
342
359
  if (shouldSkipValidation()) {
package/src/index.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { createValidator } from './helpers/validator';
2
2
  import { htmlEntityDecode } from './helpers/sanitize';
3
+ import { stringUtils } from './helpers/string';
3
4
  import * as slugUtils from './helpers/slug';
4
5
  import * as numberUtils from './helpers/number';
5
6
 
6
- export { createValidator, htmlEntityDecode, slugUtils, numberUtils };
7
+ export {
8
+ createValidator,
9
+ htmlEntityDecode,
10
+ slugUtils,
11
+ numberUtils,
12
+ stringUtils,
13
+ };