Estoy tratando de importar la función "tubería" de lodash a mi proyecto, pero aparece un error en la consola del navegador que indica que no se encuentra 404.
índice.html:
<html lang="en"> <head> <meta charset="UTF-8"> <title>Functional Programming</title> <script defer type="module" src="script.js"></script> </head> <body> <h1>Functional Programming</h1> </body> </html>paquete.json:
{ "devDependencies": { "eslint": "^8.5.0", "eslint-plugin-functional": "^4.0.2", "eslint-plugin-immutable": "^1.0.0", }, "dependencies": { "lodash": "^4.17.21" } }archivo JS:
import { pipe } from "./node_modules/lodash/fp"; const capitalize = text => text.charAt(0).toUpperCase() + text.slice(1); const shortenText = text => text.substring(0, 8).trim(); const shortText = pipe(capitalize, shortenText)("this is a long text");Solución de tubería de importación de lodash en proyecto javascript:
import { pipe } from 'lodash/fp'; const capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1); const shortenText = (text) => text.substring(0, 8).trim(); const shortText = pipe(capitalize, shortenText)('this is a long text'); console.log(shortText);para más información revisa este ejemplo: https://stackblitz.com/edit/js-zcoxit