bord-frontend-utils 0.0.1
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/README.md +70 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +25 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# bord-frontend-utils
|
|
2
|
+
|
|
3
|
+
Utilidades y hooks de React para proyectos frontend de Bord.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install bord-frontend-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Uso
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { removeAccents, useDebounce } from "bord-frontend-utils";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## API
|
|
20
|
+
|
|
21
|
+
### `removeAccents(str)`
|
|
22
|
+
|
|
23
|
+
Elimina los acentos de una cadena de texto.
|
|
24
|
+
|
|
25
|
+
| Parámetro | Tipo | Descripción |
|
|
26
|
+
| --------- | -------- | ---------------------------- |
|
|
27
|
+
| `str` | `string` | Texto con posibles acentos |
|
|
28
|
+
|
|
29
|
+
**Retorna:** `string` — el texto sin acentos.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
removeAccents("ángel García"); // → "angel Garcia"
|
|
33
|
+
removeAccents("niño"); // → "nino"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### `useDebounce<T>(value, delay)`
|
|
39
|
+
|
|
40
|
+
Hook de React que retrasa la actualización de un valor hasta que haya pasado el tiempo indicado sin cambios. Útil para inputs de búsqueda.
|
|
41
|
+
|
|
42
|
+
| Parámetro | Tipo | Descripción |
|
|
43
|
+
| --------- | -------- | ------------------------------------ |
|
|
44
|
+
| `value` | `T` | Valor a debouncear |
|
|
45
|
+
| `delay` | `number` | Tiempo de espera en milisegundos |
|
|
46
|
+
|
|
47
|
+
**Retorna:** `T` — el valor debounceado.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
const [search, setSearch] = useState("");
|
|
51
|
+
const debouncedSearch = useDebounce(search, 300);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
// Solo se ejecuta 300ms después del último cambio
|
|
55
|
+
fetchResults(debouncedSearch);
|
|
56
|
+
}, [debouncedSearch]);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Desarrollo
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm run build # genera el bundle en dist/
|
|
65
|
+
npm run dev # modo watch
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Licencia
|
|
69
|
+
|
|
70
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elimina los acentos de una cadena de texto
|
|
3
|
+
* Usa normalize NFD para descomponer los caracteres y luego elimina los diacríticos
|
|
4
|
+
* @param {string} str - Cadena de texto con posibles acentos
|
|
5
|
+
* @returns {string} Cadena de texto sin acentos
|
|
6
|
+
*/
|
|
7
|
+
declare const removeAccents: (str: string) => string;
|
|
8
|
+
|
|
9
|
+
declare const useDebounce: <T>(value: T, delay: number) => T;
|
|
10
|
+
|
|
11
|
+
export { removeAccents, useDebounce };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elimina los acentos de una cadena de texto
|
|
3
|
+
* Usa normalize NFD para descomponer los caracteres y luego elimina los diacríticos
|
|
4
|
+
* @param {string} str - Cadena de texto con posibles acentos
|
|
5
|
+
* @returns {string} Cadena de texto sin acentos
|
|
6
|
+
*/
|
|
7
|
+
declare const removeAccents: (str: string) => string;
|
|
8
|
+
|
|
9
|
+
declare const useDebounce: <T>(value: T, delay: number) => T;
|
|
10
|
+
|
|
11
|
+
export { removeAccents, useDebounce };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
removeAccents: () => removeAccents,
|
|
24
|
+
useDebounce: () => useDebounce
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/utils/removeAccents.ts
|
|
29
|
+
var removeAccents = (str) => {
|
|
30
|
+
if (!str) return str;
|
|
31
|
+
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/hooks/useDebounce.ts
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var useDebounce = (value, delay) => {
|
|
37
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react.useState)(value);
|
|
38
|
+
(0, import_react.useEffect)(() => {
|
|
39
|
+
const handler = setTimeout(() => {
|
|
40
|
+
setDebouncedValue(value);
|
|
41
|
+
}, delay);
|
|
42
|
+
return () => {
|
|
43
|
+
clearTimeout(handler);
|
|
44
|
+
};
|
|
45
|
+
}, [value, delay]);
|
|
46
|
+
return debouncedValue;
|
|
47
|
+
};
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
removeAccents,
|
|
51
|
+
useDebounce
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/removeAccents.ts","../src/hooks/useDebounce.ts"],"sourcesContent":["export { removeAccents } from \"./utils/removeAccents\";\nexport { useDebounce } from \"./hooks/useDebounce\";\n","/**\n * Elimina los acentos de una cadena de texto\n * Usa normalize NFD para descomponer los caracteres y luego elimina los diacríticos\n * @param {string} str - Cadena de texto con posibles acentos\n * @returns {string} Cadena de texto sin acentos\n */\nexport const removeAccents = (str: string): string => {\n if (!str) return str;\n return str.normalize(\"NFD\").replace(/[\\u0300-\\u036f]/g, \"\");\n};\n","import { useState, useEffect } from \"react\";\n\nexport const useDebounce = <T>(value: T, delay: number): T => {\n const [debouncedValue, setDebouncedValue] = useState<T>(value);\n\n useEffect(() => {\n const handler = setTimeout(() => {\n setDebouncedValue(value);\n }, delay);\n return () => {\n clearTimeout(handler);\n };\n }, [value, delay]);\n\n return debouncedValue;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,gBAAgB,CAAC,QAAwB;AACpD,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,IAAI,UAAU,KAAK,EAAE,QAAQ,oBAAoB,EAAE;AAC5D;;;ACTA,mBAAoC;AAE7B,IAAM,cAAc,CAAI,OAAU,UAAqB;AAC5D,QAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAAY,KAAK;AAE7D,8BAAU,MAAM;AACd,UAAM,UAAU,WAAW,MAAM;AAC/B,wBAAkB,KAAK;AAAA,IACzB,GAAG,KAAK;AACR,WAAO,MAAM;AACX,mBAAa,OAAO;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,OAAO,KAAK,CAAC;AAEjB,SAAO;AACT;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/utils/removeAccents.ts
|
|
2
|
+
var removeAccents = (str) => {
|
|
3
|
+
if (!str) return str;
|
|
4
|
+
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/hooks/useDebounce.ts
|
|
8
|
+
import { useState, useEffect } from "react";
|
|
9
|
+
var useDebounce = (value, delay) => {
|
|
10
|
+
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const handler = setTimeout(() => {
|
|
13
|
+
setDebouncedValue(value);
|
|
14
|
+
}, delay);
|
|
15
|
+
return () => {
|
|
16
|
+
clearTimeout(handler);
|
|
17
|
+
};
|
|
18
|
+
}, [value, delay]);
|
|
19
|
+
return debouncedValue;
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
removeAccents,
|
|
23
|
+
useDebounce
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/removeAccents.ts","../src/hooks/useDebounce.ts"],"sourcesContent":["/**\n * Elimina los acentos de una cadena de texto\n * Usa normalize NFD para descomponer los caracteres y luego elimina los diacríticos\n * @param {string} str - Cadena de texto con posibles acentos\n * @returns {string} Cadena de texto sin acentos\n */\nexport const removeAccents = (str: string): string => {\n if (!str) return str;\n return str.normalize(\"NFD\").replace(/[\\u0300-\\u036f]/g, \"\");\n};\n","import { useState, useEffect } from \"react\";\n\nexport const useDebounce = <T>(value: T, delay: number): T => {\n const [debouncedValue, setDebouncedValue] = useState<T>(value);\n\n useEffect(() => {\n const handler = setTimeout(() => {\n setDebouncedValue(value);\n }, delay);\n return () => {\n clearTimeout(handler);\n };\n }, [value, delay]);\n\n return debouncedValue;\n};\n"],"mappings":";AAMO,IAAM,gBAAgB,CAAC,QAAwB;AACpD,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,IAAI,UAAU,KAAK,EAAE,QAAQ,oBAAoB,EAAE;AAC5D;;;ACTA,SAAS,UAAU,iBAAiB;AAE7B,IAAM,cAAc,CAAI,OAAU,UAAqB;AAC5D,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAY,KAAK;AAE7D,YAAU,MAAM;AACd,UAAM,UAAU,WAAW,MAAM;AAC/B,wBAAkB,KAAK;AAAA,IACzB,GAAG,KAAK;AACR,WAAO,MAAM;AACX,mBAAa,OAAO;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,OAAO,KAAK,CAAC;AAEjB,SAAO;AACT;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bord-frontend-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Bord frontend utilities: reusable React hooks and helper functions for building scalable web applications.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup",
|
|
14
|
+
"dev": "tsup --watch"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react",
|
|
18
|
+
"hooks",
|
|
19
|
+
"utils",
|
|
20
|
+
"frontend",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "Bord",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "^19.2.14",
|
|
33
|
+
"tsup": "^8.5.1",
|
|
34
|
+
"typescript": "^6.0.3"
|
|
35
|
+
}
|
|
36
|
+
}
|