Use ES6 in lib files.

This commit is contained in:
John-David Dalton
2016-08-27 08:32:48 -07:00
parent 5cc02555d0
commit 94750bfa3c
13 changed files with 150 additions and 154 deletions

View File

@@ -1,11 +1,11 @@
'use strict';
var _ = require('lodash'),
fs = require('fs-extra'),
glob = require('glob'),
path = require('path');
const _ = require('lodash');
const fs = require('fs-extra');
const glob = require('glob');
const path = require('path');
var minify = require('../common/minify.js');
const minify = require('../common/minify.js');
/*----------------------------------------------------------------------------*/
@@ -30,8 +30,8 @@ function copy(srcPath, destPath) {
* @returns {Object} Returns the object of compiled templates.
*/
function globTemplate(pattern) {
return _.transform(glob.sync(pattern), function(result, filePath) {
var key = path.basename(filePath, path.extname(filePath));
return _.transform(glob.sync(pattern), (result, filePath) => {
const key = path.basename(filePath, path.extname(filePath));
result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
}, {});
}
@@ -64,8 +64,8 @@ function write(destPath, data) {
/*----------------------------------------------------------------------------*/
module.exports = {
'copy': copy,
'globTemplate': globTemplate,
'min': min,
'write': write
copy,
globTemplate,
min,
write
};

View File

@@ -1,8 +1,8 @@
'use strict';
var _mapping = require('../../fp/_mapping'),
util = require('./util'),
Hash = util.Hash;
const _mapping = require('../../fp/_mapping');
const util = require('./util');
const Hash = util.Hash;
/*----------------------------------------------------------------------------*/

View File

@@ -1,10 +1,10 @@
'use strict';
var _ = require('lodash'),
fs = require('fs-extra'),
uglify = require('uglify-js');
const _ = require('lodash');
const fs = require('fs-extra');
const uglify = require('uglify-js');
var uglifyOptions = require('./uglify.options');
const uglifyOptions = require('./uglify.options');
/*----------------------------------------------------------------------------*/
@@ -32,7 +32,7 @@ function minify(srcPath, destPath, callback, options) {
if (!destPath) {
destPath = srcPath.replace(/(?=\.js$)/, '.min');
}
var output = uglify.minify(srcPath, _.defaults(options || {}, uglifyOptions));
const output = uglify.minify(srcPath, _.defaults(options || {}, uglifyOptions));
fs.writeFile(destPath, output.code, 'utf-8', callback);
}

View File

@@ -1,6 +1,6 @@
'use strict';
var _ = require('lodash');
const _ = require('lodash');
/*----------------------------------------------------------------------------*/
@@ -13,7 +13,7 @@ var _ = require('lodash');
* @returns {Object} Returns the new hash object.
*/
function Hash(properties) {
return _.transform(properties, function(result, value, key) {
return _.transform(properties, (result, value, key) => {
result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
? new Hash(value)
: value;
@@ -35,6 +35,6 @@ function pitch(error) {
}
module.exports = {
'Hash': Hash,
'pitch': pitch
Hash,
pitch
};

View File

@@ -1,19 +1,19 @@
'use strict';
var _ = require('lodash'),
async = require('async'),
path = require('path'),
webpack = require('webpack');
const _ = require('lodash');
const async = require('async');
const path = require('path');
const webpack = require('webpack');
var file = require('../common/file'),
util = require('../common/util');
const file = require('../common/file');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
distPath = path.join(basePath, 'dist'),
fpPath = path.join(basePath, 'fp'),
filename = 'lodash.fp.js';
const basePath = path.join(__dirname, '..', '..');
const distPath = path.join(basePath, 'dist');
const fpPath = path.join(basePath, 'fp');
const filename = 'lodash.fp.js';
var fpConfig = {
const fpConfig = {
'entry': path.join(fpPath, '_convertBrowser.js'),
'output': {
'path': distPath,
@@ -27,7 +27,7 @@ var fpConfig = {
]
};
var mappingConfig = {
const mappingConfig = {
'entry': path.join(fpPath, '_mapping.js'),
'output': {
'path': distPath,

View File

@@ -1,22 +1,22 @@
'use strict';
var _ = require('lodash'),
fs = require('fs-extra'),
path = require('path');
const _ = require('lodash');
const fs = require('fs-extra');
const path = require('path');
var file = require('../common/file'),
mapping = require('../common/mapping'),
util = require('../common/util');
const file = require('../common/file');
const mapping = require('../common/mapping');
const util = require('../common/util');
var templatePath = path.join(__dirname, 'template/doc'),
template = file.globTemplate(path.join(templatePath, '*.jst'));
const templatePath = path.join(__dirname, 'template/doc');
const template = file.globTemplate(path.join(templatePath, '*.jst'));
var argNames = ['a', 'b', 'c', 'd'];
const argNames = ['a', 'b', 'c', 'd'];
var templateData = {
'mapping': mapping,
'toArgOrder': toArgOrder,
'toFuncList': toFuncList
const templateData = {
mapping,
toArgOrder,
toFuncList
};
/**
@@ -28,8 +28,8 @@ var templateData = {
* @returns {string} Returns the named argument string.
*/
function toArgOrder(indexes) {
var reordered = [];
_.each(indexes, function(newIndex, index) {
const reordered = [];
_.each(indexes, (newIndex, index) => {
reordered[newIndex] = argNames[index];
});
return '`(' + reordered.join(', ') + ')`';
@@ -43,18 +43,15 @@ function toArgOrder(indexes) {
* @returns {string} Returns the function list string.
*/
function toFuncList(funcNames) {
var chunks = _.chunk(funcNames.slice().sort(), 5),
lastChunk = _.last(chunks),
last = lastChunk ? lastChunk.pop() : undefined;
let chunks = _.chunk(funcNames.slice().sort(), 5);
let lastChunk = _.last(chunks);
const lastName = lastChunk ? lastChunk.pop() : undefined;
chunks = _.reject(chunks, _.isEmpty);
lastChunk = _.last(chunks);
var result = '`' + _.map(chunks, function(chunk) {
return chunk.join('`, `') + '`';
}).join(',\n`');
if (last == null) {
let result = '`' + _.map(chunks, chunk => chunk.join('`, `') + '`').join(',\n`');
if (lastName == null) {
return result;
}
if (_.size(chunks) > 1 || _.size(lastChunk) > 1) {
@@ -62,7 +59,7 @@ function toFuncList(funcNames) {
}
result += ' &';
result += _.size(lastChunk) < 5 ? ' ' : '\n';
return result + '`' + last + '`';
return result + '`' + lastName + '`';
}
/*----------------------------------------------------------------------------*/

View File

@@ -1,25 +1,25 @@
'use strict';
var _ = require('lodash'),
async = require('async'),
glob = require('glob'),
path = require('path');
const _ = require('lodash');
const async = require('async');
const glob = require('glob');
const path = require('path');
var file = require('../common/file'),
mapping = require('../common/mapping'),
util = require('../common/util');
const file = require('../common/file');
const mapping = require('../common/mapping');
const util = require('../common/util');
var templatePath = path.join(__dirname, 'template/modules'),
template = file.globTemplate(path.join(templatePath, '*.jst'));
const templatePath = path.join(__dirname, 'template/modules');
const template = file.globTemplate(path.join(templatePath, '*.jst'));
var aryMethods = _.union(
const aryMethods = _.union(
mapping.aryMethod[1],
mapping.aryMethod[2],
mapping.aryMethod[3],
mapping.aryMethod[4]
);
var categories = [
const categories = [
'array',
'collection',
'date',
@@ -33,7 +33,7 @@ var categories = [
'util'
];
var ignored = [
const ignored = [
'_*.js',
'core.js',
'core.min.js',
@@ -85,7 +85,7 @@ function isThru(name) {
* @returns {*} Returns the metadata for `func`.
*/
function getTemplate(moduleName) {
var data = {
const data = {
'name': _.get(mapping.aliasToReal, moduleName, moduleName),
'mapping': mapping
};
@@ -113,28 +113,28 @@ function getTemplate(moduleName) {
function build(target) {
target = path.resolve(target);
var fpPath = path.join(target, 'fp');
const fpPath = path.join(target, 'fp');
// Glob existing lodash module paths.
var modulePaths = glob.sync(path.join(target, '*.js'), {
const modulePaths = glob.sync(path.join(target, '*.js'), {
'nodir': true,
'ignore': ignored.map(function(filename) {
'ignore': ignored.map(filename => {
return path.join(target, filename);
})
});
// Add FP alias and remapped module paths.
_.each([mapping.aliasToReal, mapping.remap], function(data) {
_.forOwn(data, function(realName, alias) {
var modulePath = path.join(target, alias + '.js');
_.each([mapping.aliasToReal, mapping.remap], data => {
_.forOwn(data, (realName, alias) => {
const modulePath = path.join(target, alias + '.js');
if (!_.includes(modulePaths, modulePath)) {
modulePaths.push(modulePath);
}
});
});
var actions = modulePaths.map(function(modulePath) {
var moduleName = path.basename(modulePath, '.js');
const actions = modulePaths.map(modulePath => {
const moduleName = path.basename(modulePath, '.js');
return file.write(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
});

View File

@@ -131,8 +131,8 @@ Methods with unchanged argument orders:<br>
<%= toFuncList(_.keys(mapping.skipRearg)) %>
Methods with custom argument orders:<br>
<%= _.map(_.keys(mapping.methodRearg), function(methodName) {
var orders = mapping.methodRearg[methodName];
<%= _.map(_.keys(mapping.methodRearg), methodName => {
const orders = mapping.methodRearg[methodName];
return ' * `_.' + methodName + '` has an order of ' + toArgOrder(orders);
}).join('\n') %>
@@ -148,8 +148,8 @@ Methods created to accommodate Lodashs variadic methods:<br>
#### Aliases
There are <%= _.size(mapping.aliasToReal) %> method aliases:<br>
<%= _.map(_.keys(mapping.aliasToReal).sort(), function(alias) {
var realName = mapping.aliasToReal[alias];
<%= _.map(_.keys(mapping.aliasToReal).sort(), alias => {
const realName = mapping.aliasToReal[alias];
return ' * `_.' + alias + '` is an alias of `_.' + realName + '`';
}).join('\n') %>

View File

@@ -1,17 +1,17 @@
'use strict';
var async = require('async'),
path = require('path');
const async = require('async');
const path = require('path');
var file = require('../common/file'),
util = require('../common/util');
const file = require('../common/file');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
distPath = path.join(basePath, 'dist'),
filename = 'lodash.js';
const basePath = path.join(__dirname, '..', '..');
const distPath = path.join(basePath, 'dist');
const filename = 'lodash.js';
var baseLodash = path.join(basePath, filename),
distLodash = path.join(distPath, filename);
const baseLodash = path.join(basePath, filename);
const distLodash = path.join(distPath, filename);
/*----------------------------------------------------------------------------*/

View File

@@ -1,20 +1,20 @@
'use strict';
var _ = require('lodash'),
docdown = require('docdown'),
fs = require('fs-extra'),
path = require('path');
const _ = require('lodash');
const docdown = require('docdown');
const fs = require('fs-extra');
const path = require('path');
var util = require('../common/util');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
docPath = path.join(basePath, 'doc'),
readmePath = path.join(docPath, 'README.md');
const basePath = path.join(__dirname, '..', '..');
const docPath = path.join(basePath, 'doc');
const readmePath = path.join(docPath, 'README.md');
var pkg = require('../../package.json'),
version = pkg.version;
const pkg = require('../../package.json');
const version = pkg.version;
var config = {
const config = {
'base': {
'path': path.join(basePath, 'lodash.js'),
'title': '<a href="https://lodash.com/">lodash</a> <span>v' + version + '</span>',
@@ -74,8 +74,8 @@ function postprocess(markdown) {
* @param {string} type The format type.
*/
function build(type) {
var options = _.defaults({}, config.base, config[type]),
markdown = docdown(options);
const options = _.defaults({}, config.base, config[type]);
const markdown = docdown(options);
fs.writeFile(readmePath, postprocess(markdown), util.pitch);
}

View File

@@ -1,16 +1,16 @@
'use strict';
var _ = require('lodash'),
async = require('async'),
path = require('path');
const _ = require('lodash');
const async = require('async');
const path = require('path');
var file = require('../common/file'),
util = require('../common/util');
const file = require('../common/file');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
distPath = path.join(basePath, 'dist');
const basePath = path.join(__dirname, '..', '..');
const distPath = path.join(basePath, 'dist');
var filePairs = [
const filePairs = [
[path.join(distPath, 'lodash.core.js'), 'core.js'],
[path.join(distPath, 'lodash.core.min.js'), 'core.min.js'],
[path.join(distPath, 'lodash.min.js'), 'lodash.min.js']
@@ -25,9 +25,8 @@ var filePairs = [
* @param {string} target The output directory path.
*/
function build(target) {
var actions = _.map(filePairs, function(pair) {
return file.copy(pair[0], path.join(target, pair[1]));
});
const actions = _.map(filePairs, pair =>
file.copy(pair[0], path.join(target, pair[1])));
async.series(actions, util.pitch);
}

View File

@@ -1,41 +1,41 @@
'use strict';
var _ = require('lodash'),
fs = require('fs'),
marky = require('marky-markdown'),
path = require('path'),
util = require('../common/util');
const _ = require('lodash');
const fs = require('fs');
const marky = require('marky-markdown');
const path = require('path');
const util = require('../common/util');
var basePath = path.join(__dirname, '..', '..'),
docPath = path.join(basePath, 'doc'),
readmePath = path.join(docPath, 'README.md');
const basePath = path.join(__dirname, '..', '..');
const docPath = path.join(basePath, 'doc');
const readmePath = path.join(docPath, 'README.md');
const highlights = [
'comment',
'constant',
'delimiter',
'html',
'js',
'method',
'modifier',
'numeric',
'shell',
'source',
'string',
'text',
'type'
];
function build(type) {
var markdown = fs
const markdown = fs
// Load markdown.
.readFileSync(readmePath, 'utf8')
// Uncomment docdown HTML hints.
.replace(/(<)!--\s*|\s*--(>)/g, '$1$2');
var $ = marky(markdown, { 'sanitize': false }),
$header = $('h1').first().remove(),
version = _.trim($header.find('span').first().text()).slice(1);
var highlights = [
'comment',
'constant',
'delimiter',
'html',
'js',
'method',
'modifier',
'numeric',
'shell',
'source',
'string',
'text',
'type'
];
const $ = marky(markdown, { 'sanitize': false });
const $header = $('h1').first().remove();
const version = _.trim($header.find('span').first().text()).slice(1);
// Remove docdown horizontal rules.
$('hr').remove();
@@ -46,7 +46,7 @@ function build(type) {
.attr('id', null);
$(':header:not(h3) > a').each(function() {
var $a = $(this);
const $a = $(this);
$a.replaceWith($a.html());
});
@@ -54,8 +54,8 @@ function build(type) {
$('p:empty + h3').prev().remove();
$('h3 ~ p:empty').each(function() {
var $p = $(this),
node = this.previousSibling;
const $p = $(this);
let node = this.previousSibling;
while ((node = node.previousSibling) && node.name != 'h3' && node.name != 'p') {
$p.prepend(node.nextSibling);
@@ -63,19 +63,19 @@ function build(type) {
});
$('h3 code em').parent().each(function() {
var $code = $(this);
const $code = $(this);
$code.html($code.html().replace(/<\/?em>/g, '_'));
});
// Cleanup highlights class names.
$('.highlight [class]').each(function() {
var $el = $(this),
className = _.intersection($el.attr('class').split(/\s+/), highlights).join(' ');
const $el = $(this);
const className = _.intersection($el.attr('class').split(/\s+/), highlights).join(' ');
$el.attr('class', className || null);
});
var html = [
const html = [
// Append YAML front matter.
'---',
'id: docs',