mirror of
https://github.com/locomotivemtl/locomotive-boilerplate.git
synced 2026-01-15 00:55:08 +08:00
Move helpers/utils exports to end of file
Improves readability by always expecting exports at the end of the file.
This commit is contained in:
@@ -17,3 +17,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default loconfig;
|
export default loconfig;
|
||||||
|
|
||||||
|
export {
|
||||||
|
loconfig,
|
||||||
|
};
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ try {
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
export const supportsGlob = (typeof glob === 'function');
|
const supportsGlob = (typeof glob === 'function');
|
||||||
|
|
||||||
export default glob;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports the first available glob function.
|
* Imports the first available glob function.
|
||||||
@@ -95,3 +93,10 @@ function createArrayableGlob(glob, options) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default glob;
|
||||||
|
|
||||||
|
export {
|
||||||
|
glob,
|
||||||
|
supportsGlob,
|
||||||
|
};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import kleur from 'kleur';
|
|||||||
* @param {string} [type] - The type of message.
|
* @param {string} [type] - The type of message.
|
||||||
* @param {string} [timerID] - The console time label to output.
|
* @param {string} [timerID] - The console time label to output.
|
||||||
*/
|
*/
|
||||||
export default function message(text, type, timerID) {
|
function message(text, type, timerID) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'success':
|
case 'success':
|
||||||
console.log('✅ ', kleur.bgGreen().black(text));
|
console.log('✅ ', kleur.bgGreen().black(text));
|
||||||
@@ -52,4 +52,10 @@ export default function message(text, type, timerID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default message;
|
||||||
|
|
||||||
|
export {
|
||||||
|
message,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import notifier from 'node-notifier';
|
|||||||
* @param {function} callback - The notification callback.
|
* @param {function} callback - The notification callback.
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
export default function notification(options, callback) {
|
function notification(options, callback) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = {
|
options = {
|
||||||
message: options
|
message: options
|
||||||
@@ -42,4 +42,10 @@ export default function notification(options, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notifier.notify(options, callback);
|
notifier.notify(options, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default notification;
|
||||||
|
|
||||||
|
export {
|
||||||
|
notification,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,18 +50,14 @@ try {
|
|||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
export const supportsPostCSS = (typeof postcss === 'function');
|
const supportsPostCSS = (typeof postcss === 'function');
|
||||||
|
|
||||||
export default postcss;
|
const pluginsList = [
|
||||||
export const pluginsList = [
|
|
||||||
autoprefixer,
|
autoprefixer,
|
||||||
];
|
];
|
||||||
export const pluginsMap = {
|
const pluginsMap = {
|
||||||
'autoprefixer': autoprefixer,
|
'autoprefixer': autoprefixer,
|
||||||
};
|
};
|
||||||
export {
|
|
||||||
autoprefixer
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to create a PostCSS Processor with the given plugins and options.
|
* Attempts to create a PostCSS Processor with the given plugins and options.
|
||||||
@@ -71,7 +67,7 @@ export {
|
|||||||
* @param {PostCSSOptions} options - The PostCSS wrapper options.
|
* @param {PostCSSOptions} options - The PostCSS wrapper options.
|
||||||
* @return {?Processor}
|
* @return {?Processor}
|
||||||
*/
|
*/
|
||||||
export function createProcessor(pluginsListOrMap, options)
|
function createProcessor(pluginsListOrMap, options)
|
||||||
{
|
{
|
||||||
if (!postcss) {
|
if (!postcss) {
|
||||||
return null;
|
return null;
|
||||||
@@ -90,7 +86,7 @@ export function createProcessor(pluginsListOrMap, options)
|
|||||||
* @param {PostCSSOptions} options - The PostCSS wrapper options.
|
* @param {PostCSSOptions} options - The PostCSS wrapper options.
|
||||||
* @return {PluginList}
|
* @return {PluginList}
|
||||||
*/
|
*/
|
||||||
export function parsePlugins(pluginsListOrMap, options)
|
function parsePlugins(pluginsListOrMap, options)
|
||||||
{
|
{
|
||||||
if (Array.isArray(pluginsListOrMap)) {
|
if (Array.isArray(pluginsListOrMap)) {
|
||||||
return pluginsListOrMap;
|
return pluginsListOrMap;
|
||||||
@@ -109,3 +105,15 @@ export function parsePlugins(pluginsListOrMap, options)
|
|||||||
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default postcss;
|
||||||
|
|
||||||
|
export {
|
||||||
|
autoprefixer,
|
||||||
|
createProcessor,
|
||||||
|
parsePlugins,
|
||||||
|
pluginsList,
|
||||||
|
pluginsMap,
|
||||||
|
postcss,
|
||||||
|
supportsPostCSS,
|
||||||
|
};
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const templateData = flatten({
|
|||||||
* @param {object} [data] - An object in the form `{ 'from': 'to', … }`.
|
* @param {object} [data] - An object in the form `{ 'from': 'to', … }`.
|
||||||
* @return {*} Returns the transformed value.
|
* @return {*} Returns the transformed value.
|
||||||
*/
|
*/
|
||||||
export default function resolve(input, data = templateData) {
|
function resolve(input, data = templateData) {
|
||||||
switch (typeof input) {
|
switch (typeof input) {
|
||||||
case 'string': {
|
case 'string': {
|
||||||
return resolveValue(input, data);
|
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', … }`.
|
* @param {object} [data] - An object in the form `{ 'from': 'to', … }`.
|
||||||
* @return {string} Returns the translated string.
|
* @return {string} Returns the translated string.
|
||||||
*/
|
*/
|
||||||
export function resolveValue(input, data = templateData) {
|
function resolveValue(input, data = templateData) {
|
||||||
const tags = [];
|
const tags = [];
|
||||||
|
|
||||||
if (data !== templateData) {
|
if (data !== templateData) {
|
||||||
@@ -96,3 +96,10 @@ export function resolveValue(input, data = templateData) {
|
|||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default resolve;
|
||||||
|
|
||||||
|
export {
|
||||||
|
resolve,
|
||||||
|
resolveValue,
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,13 +2,18 @@
|
|||||||
* @file Provides generic functions and constants.
|
* @file Provides generic functions and constants.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {RegExp} - Match all special characters.
|
||||||
|
*/
|
||||||
|
const regexUnescaped = /[\[\]\{\}\(\)\-\*\+\?\.\,\\\^\$\|\#\s]/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quotes regular expression characters.
|
* Quotes regular expression characters.
|
||||||
*
|
*
|
||||||
* @param {string} str - The input string.
|
* @param {string} str - The input string.
|
||||||
* @return {string} Returns the quoted (escaped) string.
|
* @return {string} Returns the quoted (escaped) string.
|
||||||
*/
|
*/
|
||||||
export function escapeRegExp(str) {
|
function escapeRegExp(str) {
|
||||||
return str.replace(regexUnescaped, '\\$&');
|
return str.replace(regexUnescaped, '\\$&');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +46,7 @@ export function escapeRegExp(str) {
|
|||||||
* @param {object} target - The object that will receive the flattened properties.
|
* @param {object} target - The object that will receive the flattened properties.
|
||||||
* @return {object} Returns the `target` object.
|
* @return {object} Returns the `target` object.
|
||||||
*/
|
*/
|
||||||
export function flatten(input, prefix, target = {}) {
|
function flatten(input, prefix, target = {}) {
|
||||||
for (const key in input) {
|
for (const key in input) {
|
||||||
const field = (prefix ? prefix + '.' + key : key);
|
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`,
|
* @return {boolean} Returns `true` if the value is an `Object`,
|
||||||
* otherwise `false`.
|
* otherwise `false`.
|
||||||
*/
|
*/
|
||||||
export function isObjectLike(value) {
|
function isObjectLike(value) {
|
||||||
return (value != null && typeof value === 'object');
|
return (value != null && typeof value === 'object');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +80,7 @@ export function isObjectLike(value) {
|
|||||||
* @throws {TypeError} If the target and source are the same.
|
* @throws {TypeError} If the target and source are the same.
|
||||||
* @return {object} Returns the `target` object.
|
* @return {object} Returns the `target` object.
|
||||||
*/
|
*/
|
||||||
export function merge(target, ...sources) {
|
function merge(target, ...sources) {
|
||||||
for (const source of sources) {
|
for (const source of sources) {
|
||||||
if (target === source) {
|
if (target === source) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
@@ -101,7 +106,10 @@ export function merge(target, ...sources) {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export {
|
||||||
* @type {RegExp} - Match all special characters.
|
escapeRegExp,
|
||||||
*/
|
flatten,
|
||||||
export const regexUnescaped = /[\[\]\{\}\(\)\-\*\+\?\.\,\\\^\$\|\#\s]/g;
|
isObjectLike,
|
||||||
|
merge,
|
||||||
|
regexUnescaped,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user