From 9db0c71a8247f19d6807667f84e8a95e6ffd9de0 Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Thu, 13 Oct 2022 14:42:22 -0400 Subject: [PATCH] Move helpers/utils exports to end of file Improves readability by always expecting exports at the end of the file. --- build/helpers/config.js | 4 ++++ build/helpers/glob.js | 11 ++++++++--- build/helpers/message.js | 8 +++++++- build/helpers/notification.js | 8 +++++++- build/helpers/postcss.js | 26 +++++++++++++++++--------- build/helpers/template.js | 11 +++++++++-- build/utils/index.js | 24 ++++++++++++++++-------- 7 files changed, 68 insertions(+), 24 deletions(-) diff --git a/build/helpers/config.js b/build/helpers/config.js index 60a9b4a..e0a478c 100644 --- a/build/helpers/config.js +++ b/build/helpers/config.js @@ -17,3 +17,7 @@ try { } export default loconfig; + +export { + loconfig, +}; diff --git a/build/helpers/glob.js b/build/helpers/glob.js index 1f916c2..312838e 100644 --- a/build/helpers/glob.js +++ b/build/helpers/glob.js @@ -31,9 +31,7 @@ try { // do nothing } -export const supportsGlob = (typeof glob === 'function'); - -export default glob; +const supportsGlob = (typeof glob === 'function'); /** * Imports the first available glob function. @@ -95,3 +93,10 @@ function createArrayableGlob(glob, options) { }); }; } + +export default glob; + +export { + glob, + supportsGlob, +}; diff --git a/build/helpers/message.js b/build/helpers/message.js index e68d30b..dc0d4c0 100644 --- a/build/helpers/message.js +++ b/build/helpers/message.js @@ -11,7 +11,7 @@ import kleur from 'kleur'; * @param {string} [type] - The type of message. * @param {string} [timerID] - The console time label to output. */ -export default function message(text, type, timerID) { +function message(text, type, timerID) { switch (type) { case 'success': console.log('✅ ', kleur.bgGreen().black(text)); @@ -52,4 +52,10 @@ export default function message(text, type, timerID) { } console.log(''); +} + +export default message; + +export { + message, }; diff --git a/build/helpers/notification.js b/build/helpers/notification.js index b979dd9..851a4f1 100644 --- a/build/helpers/notification.js +++ b/build/helpers/notification.js @@ -16,7 +16,7 @@ import notifier from 'node-notifier'; * @param {function} callback - The notification callback. * @return {void} */ -export default function notification(options, callback) { +function notification(options, callback) { if (typeof options === 'string') { options = { message: options @@ -42,4 +42,10 @@ export default function notification(options, callback) { } notifier.notify(options, callback); +} + +export default notification; + +export { + notification, }; diff --git a/build/helpers/postcss.js b/build/helpers/postcss.js index 340ffc8..5b14955 100644 --- a/build/helpers/postcss.js +++ b/build/helpers/postcss.js @@ -50,18 +50,14 @@ try { // do nothing } -export const supportsPostCSS = (typeof postcss === 'function'); +const supportsPostCSS = (typeof postcss === 'function'); -export default postcss; -export const pluginsList = [ +const pluginsList = [ autoprefixer, ]; -export const pluginsMap = { +const pluginsMap = { 'autoprefixer': autoprefixer, }; -export { - autoprefixer -}; /** * Attempts to create a PostCSS Processor with the given plugins and options. @@ -71,7 +67,7 @@ export { * @param {PostCSSOptions} options - The PostCSS wrapper options. * @return {?Processor} */ -export function createProcessor(pluginsListOrMap, options) +function createProcessor(pluginsListOrMap, options) { if (!postcss) { return null; @@ -90,7 +86,7 @@ export function createProcessor(pluginsListOrMap, options) * @param {PostCSSOptions} options - The PostCSS wrapper options. * @return {PluginList} */ -export function parsePlugins(pluginsListOrMap, options) +function parsePlugins(pluginsListOrMap, options) { if (Array.isArray(pluginsListOrMap)) { return pluginsListOrMap; @@ -109,3 +105,15 @@ export function parsePlugins(pluginsListOrMap, options) return plugins; } + +export default postcss; + +export { + autoprefixer, + createProcessor, + parsePlugins, + pluginsList, + pluginsMap, + postcss, + supportsPostCSS, +}; diff --git a/build/helpers/template.js b/build/helpers/template.js index 1328dca..3a68440 100644 --- a/build/helpers/template.js +++ b/build/helpers/template.js @@ -26,7 +26,7 @@ const templateData = flatten({ * @param {object} [data] - An object in the form `{ 'from': 'to', … }`. * @return {*} Returns the transformed value. */ -export default function resolve(input, data = templateData) { +function resolve(input, data = templateData) { switch (typeof input) { case 'string': { return resolveValue(input, data); @@ -60,7 +60,7 @@ export default function resolve(input, data = templateData) { * @param {object} [data] - An object in the form `{ 'from': 'to', … }`. * @return {string} Returns the translated string. */ -export function resolveValue(input, data = templateData) { +function resolveValue(input, data = templateData) { const tags = []; if (data !== templateData) { @@ -96,3 +96,10 @@ export function resolveValue(input, data = templateData) { return ''; }); } + +export default resolve; + +export { + resolve, + resolveValue, +}; diff --git a/build/utils/index.js b/build/utils/index.js index 302842c..ae30355 100644 --- a/build/utils/index.js +++ b/build/utils/index.js @@ -2,13 +2,18 @@ * @file Provides generic functions and constants. */ +/** + * @type {RegExp} - Match all special characters. + */ +const regexUnescaped = /[\[\]\{\}\(\)\-\*\+\?\.\,\\\^\$\|\#\s]/g; + /** * Quotes regular expression characters. * * @param {string} str - The input string. * @return {string} Returns the quoted (escaped) string. */ -export function escapeRegExp(str) { +function escapeRegExp(str) { return str.replace(regexUnescaped, '\\$&'); } @@ -41,7 +46,7 @@ export function escapeRegExp(str) { * @param {object} target - The object that will receive the flattened properties. * @return {object} Returns the `target` object. */ -export function flatten(input, prefix, target = {}) { +function flatten(input, prefix, target = {}) { for (const key in input) { const field = (prefix ? prefix + '.' + key : key); @@ -62,7 +67,7 @@ export function flatten(input, prefix, target = {}) { * @return {boolean} Returns `true` if the value is an `Object`, * otherwise `false`. */ -export function isObjectLike(value) { +function isObjectLike(value) { return (value != null && typeof value === 'object'); } @@ -75,7 +80,7 @@ export function isObjectLike(value) { * @throws {TypeError} If the target and source are the same. * @return {object} Returns the `target` object. */ -export function merge(target, ...sources) { +function merge(target, ...sources) { for (const source of sources) { if (target === source) { throw new TypeError( @@ -101,7 +106,10 @@ export function merge(target, ...sources) { return target; } -/** - * @type {RegExp} - Match all special characters. - */ -export const regexUnescaped = /[\[\]\{\}\(\)\-\*\+\?\.\,\\\^\$\|\#\s]/g; +export { + escapeRegExp, + flatten, + isObjectLike, + merge, + regexUnescaped, +};