Skip to content

Commit

Permalink
lib: migrate to modularized lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
igorshubovych committed Feb 3, 2016
1 parent 394a0b8 commit 808b880
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ var path = require('path');
var rmdir = require('rimraf');
var cpr = require('cpr');
var wrench = require('wrench');
var _ = require('lodash');
var config = require('./config');
var remote = require('./remote');
var platform = require('./platform');
Expand Down Expand Up @@ -77,7 +76,8 @@ function isPage(file) {

function onPlatform(os) {
return function(file) {
return _.startsWith(file, 'common') || _.startsWith(file, os);
var dir = path.dirname(file);
return dir === 'common' || dir === os;
};
}

Expand Down
10 changes: 6 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var _ = require('lodash');
var defaults = require('lodash.defaults');
var compact = require('lodash.compact');
var map = require('lodash.map');
var fs = require('fs');
var path = require('path');
var osHomedir = require('os-homedir');
Expand Down Expand Up @@ -29,10 +31,10 @@ function load() {
/*eslint-enable */
}

var merged = _.defaultsDeep(customConfig, defaultConfig);
var errors = _.map(merged.colors, validateColor);
var merged = defaults(customConfig, defaultConfig);
var errors = map(merged.colors, validateColor);
errors.push(validatePlatform(merged.platform));
errors = _.compact(errors);
errors = compact(errors);

if (errors.length === 0) {
return merged;
Expand Down
9 changes: 5 additions & 4 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('lodash');
var last = require('lodash.last');
var unescape = require('lodash.unescape');
var marked = require('marked');

var allElements = [
Expand All @@ -9,7 +10,7 @@ var allElements = [

function unhtml(text){
text = text.replace(/<code>/, '').replace(/<\/code>/, '');
return _.unescape(text);
return unescape(text);
}

exports.parse = function(markdown) {
Expand All @@ -30,7 +31,7 @@ exports.parse = function(markdown) {
// paragraphs just pass through (automatically created by new lines)
r.paragraph = function(text) {
if (/^<code>.*<\/code>$/.test(text)) {
var example = _.last(page.examples);
var example = last(page.examples);
if (example) {
example.code = unhtml(text);
}
Expand All @@ -51,7 +52,7 @@ exports.parse = function(markdown) {

r.listitem = function(text) {
page.examples.push({});
_.last(page.examples).description = unhtml(text);
last(page.examples).description = unhtml(text);
};

marked(markdown, {renderer: r, sanitize: true});
Expand Down
8 changes: 4 additions & 4 deletions lib/tldr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _ = require('lodash');
var sample = require('lodash.sample');
var fs = require('fs');
var ms = require('ms');
var path = require('path');
Expand Down Expand Up @@ -45,7 +45,7 @@ exports.random = function() {
console.error(messages.emptyCache());
exit(1);
}
var page = _.sample(pages);
var page = sample(pages);
console.log('PAGE', page);
printBestPage([page]);
});
Expand All @@ -57,7 +57,7 @@ exports.randomExample = function() {
console.error(messages.emptyCache());
exit(1);
}
var page = _.sample(pages);
var page = sample(pages);
console.log('PAGE', page);
printBestPage([page], {randomExample: true});
});
Expand Down Expand Up @@ -109,7 +109,7 @@ function printBestPage(pages, options) {
checkStale();
var page = parser.parse(content);
if (options && options.randomExample === true) {
page.examples = [_.sample(page.examples)];
page.examples = [sample(page.examples)];
}
var output = render.toANSI(page);
console.log(output);
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@
"colors": "~1.1.2",
"commander": "~2.9.0",
"cpr": "~1.0.0",
"lodash": "~3.10.1",
"lodash.compact": "~3.0.0",
"lodash.defaults": "~4.0.1",
"lodash.last": "~3.0.0",
"lodash.map": "~4.0.2",
"lodash.sample": "~4.0.1",
"lodash.unescape": "~3.1.2",
"marked": "~0.3.5",
"mkdirp": "~0.5.1",
"ms": "~0.7.1",
Expand Down

0 comments on commit 808b880

Please sign in to comment.