Reputation: 143
I am working on Currying topic from Mostly Adequate Guide by Professor Frisby, I try to install lodash via npm
after realize browser can't run require()
. I've been through searching here to use similar solutions but doesn't work, I want to make it run on Node on local server or using script
, still same results below and also ramda
.
Error: Cannot find module 'lodash.curry'
at Function.Module._resolveFilename (module.js:327:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:355:17)
at require (internal/module.js:13:17)
at Object.<anonymous> (/Users/hueke32/Desktop/lodash_test/lodashTest.js:1:13)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Function.Module.runMain (module.js:431:10)
Package.json
{
"name": "lodash_test",
"version": "1.0.0",
"description": "",
"main": "lodashTest.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"browser-sync": "^2.11.0",
"lodash": "^3.10.1"
}
}
lodashTest.js
var curry = require('lodash.curry');
var match = curry(function(what, str) {
return str.match(what);
});
var replace = curry(function(what, replacement, str) {
return str.replace(what, replacement);
});
var filter = curry(function(f, ary) {
return ary.filter(f);
});
var map = curry(function(f, ary) {
return ary.map(f);
});
match(/\s+/g, "hello world");
match(/\s+/g)("hello world");
var hasSpaces = match(/\s+/g);
hasSpaces("hello world");
hasSpaces("spaceless");
filter(hasSpaces, ["tori_spelling", "tori amos"]);
var findSpaces = filter(hasSpaces);
findSpaces(["tori_spelling", "tori amos"]);
var noVowels = replace(/[aeiou]/ig);
var censored = noVowels("*");
censored("Chocolate Rain");
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="lodashTest.js"></script>
</head>
<body>
</body>
</html>
Upvotes: 1
Views: 326
Reputation: 349
lodash.curry
is not a module. lodash
is a module with curry
as a member. You should correct your require like below.
var curry = require('lodash').curry;
Upvotes: 1