mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Use ES6 in lib files.
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
delete global['__core-js_shared__'];
|
delete global['__core-js_shared__'];
|
||||||
|
|
||||||
var _ = require('./lodash.js'),
|
const _ = require('./lodash.js');
|
||||||
globals = require('lodash-doc-globals');
|
const globals = require('lodash-doc-globals');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'babel': false,
|
'babel': false,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
fs = require('fs-extra'),
|
const fs = require('fs-extra');
|
||||||
glob = require('glob'),
|
const glob = require('glob');
|
||||||
path = require('path');
|
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.
|
* @returns {Object} Returns the object of compiled templates.
|
||||||
*/
|
*/
|
||||||
function globTemplate(pattern) {
|
function globTemplate(pattern) {
|
||||||
return _.transform(glob.sync(pattern), function(result, filePath) {
|
return _.transform(glob.sync(pattern), (result, filePath) => {
|
||||||
var key = path.basename(filePath, path.extname(filePath));
|
const key = path.basename(filePath, path.extname(filePath));
|
||||||
result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
|
result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,8 @@ function write(destPath, data) {
|
|||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'copy': copy,
|
copy,
|
||||||
'globTemplate': globTemplate,
|
globTemplate,
|
||||||
'min': min,
|
min,
|
||||||
'write': write
|
write
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _mapping = require('../../fp/_mapping'),
|
const _mapping = require('../../fp/_mapping');
|
||||||
util = require('./util'),
|
const util = require('./util');
|
||||||
Hash = util.Hash;
|
const Hash = util.Hash;
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
fs = require('fs-extra'),
|
const fs = require('fs-extra');
|
||||||
uglify = require('uglify-js');
|
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) {
|
if (!destPath) {
|
||||||
destPath = srcPath.replace(/(?=\.js$)/, '.min');
|
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);
|
fs.writeFile(destPath, output.code, 'utf-8', callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ var _ = require('lodash');
|
|||||||
* @returns {Object} Returns the new hash object.
|
* @returns {Object} Returns the new hash object.
|
||||||
*/
|
*/
|
||||||
function Hash(properties) {
|
function Hash(properties) {
|
||||||
return _.transform(properties, function(result, value, key) {
|
return _.transform(properties, (result, value, key) => {
|
||||||
result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
|
result[key] = (_.isPlainObject(value) && !(value instanceof Hash))
|
||||||
? new Hash(value)
|
? new Hash(value)
|
||||||
: value;
|
: value;
|
||||||
@@ -35,6 +35,6 @@ function pitch(error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'Hash': Hash,
|
Hash,
|
||||||
'pitch': pitch
|
pitch
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
async = require('async'),
|
const async = require('async');
|
||||||
path = require('path'),
|
const path = require('path');
|
||||||
webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
|
|
||||||
var file = require('../common/file'),
|
const file = require('../common/file');
|
||||||
util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
const basePath = path.join(__dirname, '..', '..');
|
||||||
distPath = path.join(basePath, 'dist'),
|
const distPath = path.join(basePath, 'dist');
|
||||||
fpPath = path.join(basePath, 'fp'),
|
const fpPath = path.join(basePath, 'fp');
|
||||||
filename = 'lodash.fp.js';
|
const filename = 'lodash.fp.js';
|
||||||
|
|
||||||
var fpConfig = {
|
const fpConfig = {
|
||||||
'entry': path.join(fpPath, '_convertBrowser.js'),
|
'entry': path.join(fpPath, '_convertBrowser.js'),
|
||||||
'output': {
|
'output': {
|
||||||
'path': distPath,
|
'path': distPath,
|
||||||
@@ -27,7 +27,7 @@ var fpConfig = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
var mappingConfig = {
|
const mappingConfig = {
|
||||||
'entry': path.join(fpPath, '_mapping.js'),
|
'entry': path.join(fpPath, '_mapping.js'),
|
||||||
'output': {
|
'output': {
|
||||||
'path': distPath,
|
'path': distPath,
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
fs = require('fs-extra'),
|
const fs = require('fs-extra');
|
||||||
path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var file = require('../common/file'),
|
const file = require('../common/file');
|
||||||
mapping = require('../common/mapping'),
|
const mapping = require('../common/mapping');
|
||||||
util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var templatePath = path.join(__dirname, 'template/doc'),
|
const templatePath = path.join(__dirname, 'template/doc');
|
||||||
template = file.globTemplate(path.join(templatePath, '*.jst'));
|
const template = file.globTemplate(path.join(templatePath, '*.jst'));
|
||||||
|
|
||||||
var argNames = ['a', 'b', 'c', 'd'];
|
const argNames = ['a', 'b', 'c', 'd'];
|
||||||
|
|
||||||
var templateData = {
|
const templateData = {
|
||||||
'mapping': mapping,
|
mapping,
|
||||||
'toArgOrder': toArgOrder,
|
toArgOrder,
|
||||||
'toFuncList': toFuncList
|
toFuncList
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,8 +28,8 @@ var templateData = {
|
|||||||
* @returns {string} Returns the named argument string.
|
* @returns {string} Returns the named argument string.
|
||||||
*/
|
*/
|
||||||
function toArgOrder(indexes) {
|
function toArgOrder(indexes) {
|
||||||
var reordered = [];
|
const reordered = [];
|
||||||
_.each(indexes, function(newIndex, index) {
|
_.each(indexes, (newIndex, index) => {
|
||||||
reordered[newIndex] = argNames[index];
|
reordered[newIndex] = argNames[index];
|
||||||
});
|
});
|
||||||
return '`(' + reordered.join(', ') + ')`';
|
return '`(' + reordered.join(', ') + ')`';
|
||||||
@@ -43,18 +43,15 @@ function toArgOrder(indexes) {
|
|||||||
* @returns {string} Returns the function list string.
|
* @returns {string} Returns the function list string.
|
||||||
*/
|
*/
|
||||||
function toFuncList(funcNames) {
|
function toFuncList(funcNames) {
|
||||||
var chunks = _.chunk(funcNames.slice().sort(), 5),
|
let chunks = _.chunk(funcNames.slice().sort(), 5);
|
||||||
lastChunk = _.last(chunks),
|
let lastChunk = _.last(chunks);
|
||||||
last = lastChunk ? lastChunk.pop() : undefined;
|
const lastName = lastChunk ? lastChunk.pop() : undefined;
|
||||||
|
|
||||||
chunks = _.reject(chunks, _.isEmpty);
|
chunks = _.reject(chunks, _.isEmpty);
|
||||||
lastChunk = _.last(chunks);
|
lastChunk = _.last(chunks);
|
||||||
|
|
||||||
var result = '`' + _.map(chunks, function(chunk) {
|
let result = '`' + _.map(chunks, chunk => chunk.join('`, `') + '`').join(',\n`');
|
||||||
return chunk.join('`, `') + '`';
|
if (lastName == null) {
|
||||||
}).join(',\n`');
|
|
||||||
|
|
||||||
if (last == null) {
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (_.size(chunks) > 1 || _.size(lastChunk) > 1) {
|
if (_.size(chunks) > 1 || _.size(lastChunk) > 1) {
|
||||||
@@ -62,7 +59,7 @@ function toFuncList(funcNames) {
|
|||||||
}
|
}
|
||||||
result += ' &';
|
result += ' &';
|
||||||
result += _.size(lastChunk) < 5 ? ' ' : '\n';
|
result += _.size(lastChunk) < 5 ? ' ' : '\n';
|
||||||
return result + '`' + last + '`';
|
return result + '`' + lastName + '`';
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
async = require('async'),
|
const async = require('async');
|
||||||
glob = require('glob'),
|
const glob = require('glob');
|
||||||
path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var file = require('../common/file'),
|
const file = require('../common/file');
|
||||||
mapping = require('../common/mapping'),
|
const mapping = require('../common/mapping');
|
||||||
util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var templatePath = path.join(__dirname, 'template/modules'),
|
const templatePath = path.join(__dirname, 'template/modules');
|
||||||
template = file.globTemplate(path.join(templatePath, '*.jst'));
|
const template = file.globTemplate(path.join(templatePath, '*.jst'));
|
||||||
|
|
||||||
var aryMethods = _.union(
|
const aryMethods = _.union(
|
||||||
mapping.aryMethod[1],
|
mapping.aryMethod[1],
|
||||||
mapping.aryMethod[2],
|
mapping.aryMethod[2],
|
||||||
mapping.aryMethod[3],
|
mapping.aryMethod[3],
|
||||||
mapping.aryMethod[4]
|
mapping.aryMethod[4]
|
||||||
);
|
);
|
||||||
|
|
||||||
var categories = [
|
const categories = [
|
||||||
'array',
|
'array',
|
||||||
'collection',
|
'collection',
|
||||||
'date',
|
'date',
|
||||||
@@ -33,7 +33,7 @@ var categories = [
|
|||||||
'util'
|
'util'
|
||||||
];
|
];
|
||||||
|
|
||||||
var ignored = [
|
const ignored = [
|
||||||
'_*.js',
|
'_*.js',
|
||||||
'core.js',
|
'core.js',
|
||||||
'core.min.js',
|
'core.min.js',
|
||||||
@@ -85,7 +85,7 @@ function isThru(name) {
|
|||||||
* @returns {*} Returns the metadata for `func`.
|
* @returns {*} Returns the metadata for `func`.
|
||||||
*/
|
*/
|
||||||
function getTemplate(moduleName) {
|
function getTemplate(moduleName) {
|
||||||
var data = {
|
const data = {
|
||||||
'name': _.get(mapping.aliasToReal, moduleName, moduleName),
|
'name': _.get(mapping.aliasToReal, moduleName, moduleName),
|
||||||
'mapping': mapping
|
'mapping': mapping
|
||||||
};
|
};
|
||||||
@@ -113,28 +113,28 @@ function getTemplate(moduleName) {
|
|||||||
function build(target) {
|
function build(target) {
|
||||||
target = path.resolve(target);
|
target = path.resolve(target);
|
||||||
|
|
||||||
var fpPath = path.join(target, 'fp');
|
const fpPath = path.join(target, 'fp');
|
||||||
|
|
||||||
// Glob existing lodash module paths.
|
// Glob existing lodash module paths.
|
||||||
var modulePaths = glob.sync(path.join(target, '*.js'), {
|
const modulePaths = glob.sync(path.join(target, '*.js'), {
|
||||||
'nodir': true,
|
'nodir': true,
|
||||||
'ignore': ignored.map(function(filename) {
|
'ignore': ignored.map(filename => {
|
||||||
return path.join(target, filename);
|
return path.join(target, filename);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add FP alias and remapped module paths.
|
// Add FP alias and remapped module paths.
|
||||||
_.each([mapping.aliasToReal, mapping.remap], function(data) {
|
_.each([mapping.aliasToReal, mapping.remap], data => {
|
||||||
_.forOwn(data, function(realName, alias) {
|
_.forOwn(data, (realName, alias) => {
|
||||||
var modulePath = path.join(target, alias + '.js');
|
const modulePath = path.join(target, alias + '.js');
|
||||||
if (!_.includes(modulePaths, modulePath)) {
|
if (!_.includes(modulePaths, modulePath)) {
|
||||||
modulePaths.push(modulePath);
|
modulePaths.push(modulePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var actions = modulePaths.map(function(modulePath) {
|
const actions = modulePaths.map(modulePath => {
|
||||||
var moduleName = path.basename(modulePath, '.js');
|
const moduleName = path.basename(modulePath, '.js');
|
||||||
return file.write(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
return file.write(path.join(fpPath, moduleName + '.js'), getTemplate(moduleName));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ Methods with unchanged argument orders:<br>
|
|||||||
<%= toFuncList(_.keys(mapping.skipRearg)) %>
|
<%= toFuncList(_.keys(mapping.skipRearg)) %>
|
||||||
|
|
||||||
Methods with custom argument orders:<br>
|
Methods with custom argument orders:<br>
|
||||||
<%= _.map(_.keys(mapping.methodRearg), function(methodName) {
|
<%= _.map(_.keys(mapping.methodRearg), methodName => {
|
||||||
var orders = mapping.methodRearg[methodName];
|
const orders = mapping.methodRearg[methodName];
|
||||||
return ' * `_.' + methodName + '` has an order of ' + toArgOrder(orders);
|
return ' * `_.' + methodName + '` has an order of ' + toArgOrder(orders);
|
||||||
}).join('\n') %>
|
}).join('\n') %>
|
||||||
|
|
||||||
@@ -148,8 +148,8 @@ Methods created to accommodate Lodash’s variadic methods:<br>
|
|||||||
#### Aliases
|
#### Aliases
|
||||||
|
|
||||||
There are <%= _.size(mapping.aliasToReal) %> method aliases:<br>
|
There are <%= _.size(mapping.aliasToReal) %> method aliases:<br>
|
||||||
<%= _.map(_.keys(mapping.aliasToReal).sort(), function(alias) {
|
<%= _.map(_.keys(mapping.aliasToReal).sort(), alias => {
|
||||||
var realName = mapping.aliasToReal[alias];
|
const realName = mapping.aliasToReal[alias];
|
||||||
return ' * `_.' + alias + '` is an alias of `_.' + realName + '`';
|
return ' * `_.' + alias + '` is an alias of `_.' + realName + '`';
|
||||||
}).join('\n') %>
|
}).join('\n') %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
const async = require('async');
|
||||||
path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var file = require('../common/file'),
|
const file = require('../common/file');
|
||||||
util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
const basePath = path.join(__dirname, '..', '..');
|
||||||
distPath = path.join(basePath, 'dist'),
|
const distPath = path.join(basePath, 'dist');
|
||||||
filename = 'lodash.js';
|
const filename = 'lodash.js';
|
||||||
|
|
||||||
var baseLodash = path.join(basePath, filename),
|
const baseLodash = path.join(basePath, filename);
|
||||||
distLodash = path.join(distPath, filename);
|
const distLodash = path.join(distPath, filename);
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
docdown = require('docdown'),
|
const docdown = require('docdown');
|
||||||
fs = require('fs-extra'),
|
const fs = require('fs-extra');
|
||||||
path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
const basePath = path.join(__dirname, '..', '..');
|
||||||
docPath = path.join(basePath, 'doc'),
|
const docPath = path.join(basePath, 'doc');
|
||||||
readmePath = path.join(docPath, 'README.md');
|
const readmePath = path.join(docPath, 'README.md');
|
||||||
|
|
||||||
var pkg = require('../../package.json'),
|
const pkg = require('../../package.json');
|
||||||
version = pkg.version;
|
const version = pkg.version;
|
||||||
|
|
||||||
var config = {
|
const config = {
|
||||||
'base': {
|
'base': {
|
||||||
'path': path.join(basePath, 'lodash.js'),
|
'path': path.join(basePath, 'lodash.js'),
|
||||||
'title': '<a href="https://lodash.com/">lodash</a> <span>v' + version + '</span>',
|
'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.
|
* @param {string} type The format type.
|
||||||
*/
|
*/
|
||||||
function build(type) {
|
function build(type) {
|
||||||
var options = _.defaults({}, config.base, config[type]),
|
const options = _.defaults({}, config.base, config[type]);
|
||||||
markdown = docdown(options);
|
const markdown = docdown(options);
|
||||||
|
|
||||||
fs.writeFile(readmePath, postprocess(markdown), util.pitch);
|
fs.writeFile(readmePath, postprocess(markdown), util.pitch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
async = require('async'),
|
const async = require('async');
|
||||||
path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
var file = require('../common/file'),
|
const file = require('../common/file');
|
||||||
util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
const basePath = path.join(__dirname, '..', '..');
|
||||||
distPath = path.join(basePath, 'dist');
|
const distPath = path.join(basePath, 'dist');
|
||||||
|
|
||||||
var filePairs = [
|
const filePairs = [
|
||||||
[path.join(distPath, 'lodash.core.js'), 'core.js'],
|
[path.join(distPath, 'lodash.core.js'), 'core.js'],
|
||||||
[path.join(distPath, 'lodash.core.min.js'), 'core.min.js'],
|
[path.join(distPath, 'lodash.core.min.js'), 'core.min.js'],
|
||||||
[path.join(distPath, 'lodash.min.js'), 'lodash.min.js']
|
[path.join(distPath, 'lodash.min.js'), 'lodash.min.js']
|
||||||
@@ -25,9 +25,8 @@ var filePairs = [
|
|||||||
* @param {string} target The output directory path.
|
* @param {string} target The output directory path.
|
||||||
*/
|
*/
|
||||||
function build(target) {
|
function build(target) {
|
||||||
var actions = _.map(filePairs, function(pair) {
|
const actions = _.map(filePairs, pair =>
|
||||||
return file.copy(pair[0], path.join(target, pair[1]));
|
file.copy(pair[0], path.join(target, pair[1])));
|
||||||
});
|
|
||||||
|
|
||||||
async.series(actions, util.pitch);
|
async.series(actions, util.pitch);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash'),
|
const _ = require('lodash');
|
||||||
fs = require('fs'),
|
const fs = require('fs');
|
||||||
marky = require('marky-markdown'),
|
const marky = require('marky-markdown');
|
||||||
path = require('path'),
|
const path = require('path');
|
||||||
util = require('../common/util');
|
const util = require('../common/util');
|
||||||
|
|
||||||
var basePath = path.join(__dirname, '..', '..'),
|
const basePath = path.join(__dirname, '..', '..');
|
||||||
docPath = path.join(basePath, 'doc'),
|
const docPath = path.join(basePath, 'doc');
|
||||||
readmePath = path.join(docPath, 'README.md');
|
const readmePath = path.join(docPath, 'README.md');
|
||||||
|
|
||||||
function build(type) {
|
const highlights = [
|
||||||
var 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',
|
'comment',
|
||||||
'constant',
|
'constant',
|
||||||
'delimiter',
|
'delimiter',
|
||||||
@@ -37,6 +26,17 @@ function build(type) {
|
|||||||
'type'
|
'type'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function build(type) {
|
||||||
|
const markdown = fs
|
||||||
|
// Load markdown.
|
||||||
|
.readFileSync(readmePath, 'utf8')
|
||||||
|
// Uncomment docdown HTML hints.
|
||||||
|
.replace(/(<)!--\s*|\s*--(>)/g, '$1$2');
|
||||||
|
|
||||||
|
const $ = marky(markdown, { 'sanitize': false });
|
||||||
|
const $header = $('h1').first().remove();
|
||||||
|
const version = _.trim($header.find('span').first().text()).slice(1);
|
||||||
|
|
||||||
// Remove docdown horizontal rules.
|
// Remove docdown horizontal rules.
|
||||||
$('hr').remove();
|
$('hr').remove();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ function build(type) {
|
|||||||
.attr('id', null);
|
.attr('id', null);
|
||||||
|
|
||||||
$(':header:not(h3) > a').each(function() {
|
$(':header:not(h3) > a').each(function() {
|
||||||
var $a = $(this);
|
const $a = $(this);
|
||||||
$a.replaceWith($a.html());
|
$a.replaceWith($a.html());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@ function build(type) {
|
|||||||
$('p:empty + h3').prev().remove();
|
$('p:empty + h3').prev().remove();
|
||||||
|
|
||||||
$('h3 ~ p:empty').each(function() {
|
$('h3 ~ p:empty').each(function() {
|
||||||
var $p = $(this),
|
const $p = $(this);
|
||||||
node = this.previousSibling;
|
let node = this.previousSibling;
|
||||||
|
|
||||||
while ((node = node.previousSibling) && node.name != 'h3' && node.name != 'p') {
|
while ((node = node.previousSibling) && node.name != 'h3' && node.name != 'p') {
|
||||||
$p.prepend(node.nextSibling);
|
$p.prepend(node.nextSibling);
|
||||||
@@ -63,19 +63,19 @@ function build(type) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('h3 code em').parent().each(function() {
|
$('h3 code em').parent().each(function() {
|
||||||
var $code = $(this);
|
const $code = $(this);
|
||||||
$code.html($code.html().replace(/<\/?em>/g, '_'));
|
$code.html($code.html().replace(/<\/?em>/g, '_'));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cleanup highlights class names.
|
// Cleanup highlights class names.
|
||||||
$('.highlight [class]').each(function() {
|
$('.highlight [class]').each(function() {
|
||||||
var $el = $(this),
|
const $el = $(this);
|
||||||
className = _.intersection($el.attr('class').split(/\s+/), highlights).join(' ');
|
const className = _.intersection($el.attr('class').split(/\s+/), highlights).join(' ');
|
||||||
|
|
||||||
$el.attr('class', className || null);
|
$el.attr('class', className || null);
|
||||||
});
|
});
|
||||||
|
|
||||||
var html = [
|
const html = [
|
||||||
// Append YAML front matter.
|
// Append YAML front matter.
|
||||||
'---',
|
'---',
|
||||||
'id: docs',
|
'id: docs',
|
||||||
|
|||||||
Reference in New Issue
Block a user