I am trying to import "pipe" function from lodash into my project but I get error in browser console that it's not found 404.
index.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>
package.json:
{
"devDependencies": {
"eslint": "^8.5.0",
"eslint-plugin-functional": "^4.0.2",
"eslint-plugin-immutable": "^1.0.0",
},
"dependencies": {
"lodash": "^4.17.21"
}
}
JS file:
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");
Solution of import pipe from lodash into javascript project:
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);
for more information check this example: https://stackblitz.com/edit/js-zcoxit