1.4.6 • Published 1 year ago

fepper-utils v1.4.6

Weekly downloads
147
License
MIT
Repository
github
Last release
1 year ago

Fepper Utilities

If you are creating a Fepper extension:

npm install --save fepper-utils

Then, require in your JavaScript:

const utils = require('fepper-utils');
const property = utils.deepGet(obj, 'path.to.nested.property');

Functions

t(key) ⇒ string

Translate using an English key.

Kind: exported function
Returns: string - The phrase in another language (or an English alternative).

ParamTypeDescription
keystringThe phrase in English.

beautifyTemplate(extendedTemplate) ⇒ string

Beautify an HTML-like template. Any Feplet/Mustache code within will be beautified as well.

Kind: exported function
Returns: string - The beautified template code.

ParamTypeDescription
extendedTemplatestringThe string contents of an HTML-like template.

deepGet(obj, path) ⇒ * | null

Get data from a nested property within an object.

Kind: exported function
Returns: * | null - The retrieved data or null on failure.

ParamTypeDescription
objobjectThe object from which to get the data.
pathstring | arrayDot-notation string to the nested property, or array of keys if dot-notation won't work.

extendButNotOverride(...objects) ⇒ object

Recursively merge properties of two or more objects into the first object.

Kind: exported function
Returns: object - The mutated first object.

ParamTypeDescription
...objectsobjectThe objects to get merged. The first object will not have its properties overwritten. It will be extended with additional properties from the additional objects. Since the first object gets mutated, the return value is only necessary for referencing to a new variable.

regexReservedCharsEscape(regexStr) ⇒ string

Escape reserved regular expression characters.

Kind: exported function
Returns: string - A regular expression with escaped reserved characters.

ParamTypeDescription
regexStrstringThe regular expression with unescaped reserved characters.

shuffle(a) ⇒ array

Shuffle the elements of an array with the Fisher-Yates algorithm.

Kind: exported function
Returns: array - Shuffled array.
See

ParamTypeDescription
aarrayArray to be shuffled. Since a gets mutated, the return value is only necessary for the purpose of referencing to a new variable.

strReplaceGlobal(haystack, needle, replacement) ⇒ string

More efficient global string replace than String.prototype.replace.

Kind: exported function
Returns: string - Modified full string.

ParamTypeDescription
haystackstringFull string to be modified.
needlestringThe substring to be replaced.
replacementstringThe substring to replace needle.

backendDirCheck(backendDir) ⇒ string

Validate existence of a backend subdirectory.

Kind: exported function
Returns: string - A valid absolute path to the backend subdirectory, or an empty string.

ParamTypeDescription
backendDirstringThe path to a subdirectory of the backend.

rmRfFilesNotDirs(dirToEmpty)

Recursively empty a directory of files, but not nested directories.

Kind: exported function

ParamTypeDescription
dirToEmptystringDirectory to empty.

extNormalize(ext) ⇒ string

Normalize a file extension. Ensure that it is trimmed of extraneous whitespace, contains only valid characters, and is prepended with a dot if it was omitted as the first valid character.

Kind: exported function
Returns: string - A normalized file extension, or an empty string if it fails validation.

ParamTypeDescription
extstringFile extension.

findup(filename, workDir) ⇒ string

Search the file system from a starting directory upward.

Kind: exported function
Returns: string - The absolute path to the found file or an empty string if the search fails.

ParamTypeDescription
filenamestringThe file being searched for.
workDirstringThe absolute path where the search starts.

pathResolve(...pathSegments) ⇒ string

Concatenate and normalize path segments, and also ensure that path separators are forward-slashes. Resolution will not occur with the file system, so relative paths will stay relative and wrong paths will stay wrong. Accepts string arguments to be concatenated into a forward-slash separated path.

Kind: exported function
Returns: string - Path.

ParamTypeDescription
...pathSegmentsstringPath or path segments.

uiConfigNormalize(uiObj, workDir, appDir) ⇒ object

Normalize UI config values. Strip leading dot+slashes and trailing slashes from relative paths and save. Turn relative paths into absolute paths and save. Prepend leading dots to extension nnames if necessary.

Kind: exported function
Returns: object - The mutated uiObj.

ParamTypeDescription
uiObjobjectThe UI configuration object. Since uiObj gets mutated, the return value is only necessary for the purpose of referencing to a new variable.
workDirstringThe absolute path to the directory directly above the relative paths in the uiObj.
appDirstringThe absolute path to the fepper-npm directory. Only necessary when Pattern Lab is instantiated without Fepper.

error(...args)

Abstract console.error to not trigger lint warnings/errors. Outputs the error in red text.

Kind: exported function

ParamTypeDescription
...args*Same arguments as console.error.

i(obj, depth, showHidden)

"i" for "inspect". Shorthand for util.inspect or console.dir. This exists primarily for internal debugging.

Kind: exported function

ParamTypeDefaultDescription
objobjectThe object to inspect.
depthnull | numbernullNumber of times to recurse while inspecting the object. null means infinity.
showHiddenbooleanfalseWhether the object's non-enumerable properties will be included in the result.

info(...args)

Abstract console.info to not trigger lint warnings/errors. Outputs the info in green text.

Kind: exported function

ParamTypeDescription
...args*Same arguments as console.info.

log(...args)

Abstract console.log to not trigger lint warnings/errors.

Kind: exported function

ParamTypeDescription
...args*Same arguments as console.log.

warn(...args)

Abstract console.warn to not trigger lint warnings/errors. Outputs the warning in yellow text.

Kind: exported function

ParamTypeDescription
...args*Same arguments as console.warn.

webservedDirnamesTruncate(webservedDirsFull) ⇒ array

Remove first path segment from values in webservedDirsFull array. Return a new array composed of these new values.

Kind: exported function
Returns: array - The webserved directories stripped of configuration prefix.

ParamTypeDescription
webservedDirsFullarrayThe array of webserved directories.

webservedDirsCopy(webservedDirsFull, webservedDirsShort, staticDir)

Copy webserved dirs to static site dir.

Kind: exported function

ParamTypeDescription
webservedDirsFullarrayPath to directories webserved by Fepper.
webservedDirsShortarrayPath to directories webserved by Fepper truncated for publishing to static site.
staticDirstringThe destination directory.
1.4.6

1 year ago

1.4.6-rc.0

1 year ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

4 years ago

1.4.0-rc.0

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.7-rc.0

4 years ago

1.3.6

4 years ago

1.3.6-rc.0

4 years ago

1.3.5

4 years ago

1.3.5-rc.0

4 years ago

1.3.4

4 years ago

1.3.4-rc.0

4 years ago

1.3.3

4 years ago

1.3.2

5 years ago

1.3.2-rc.0

5 years ago

1.3.1

5 years ago

1.3.1-rc.1

5 years ago

1.3.1-rc.0

5 years ago

1.3.0

5 years ago

1.2.4-rc.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.7

5 years ago

1.1.7-rc.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.1.0-rc.0

6 years ago

1.0.4

6 years ago

1.0.4-rc.0

6 years ago

1.0.3

6 years ago

1.0.3-rc.1

6 years ago

1.0.3-rc.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago