Fepper Utilities
If you are creating a Fepper extension:
npm install --save fepper-utils
Then, require in your JavaScript:
const utils = require('fepper-utils');
Functions
- extendButNotOverride(obj1, obj2) ⇒
object
Recursively merge properties of two objects.
- regexReservedCharsEscape(regexStr) ⇒
string
Escape reserved regular expression characters.
- shuffle(a) ⇒
array
Shuffle the elements of an array with the Fisher-Yates algorithm.
- backendDirCheck(backendDir) ⇒
string
Validate existence of a backend subdirectory.
- 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.
- findup(filename, workDir) ⇒
string
Search the file system from a starting directory upward.
- pathResolve() ⇒
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.
- uiConfigNormalize(uiObj, workDir) ⇒
object
Normalize UI config values.
Turn relative paths into absolute paths.
Prepend leading dots to extnames if necessary.
- error()
Abstract console.error to not trigger lint warnings/errors.
Outputs the error in red text.
Accepts the 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. Be sure to remove invocations when done because they won't pass lint.
- info()
Abstract console.info to not trigger lint warnings/errors.
Outputs the info in green text.
Accepts the same arguments as console.info.
- log()
Abstract console.log to not trigger lint warnings/errors.
Accepts the same arguments as console.log.
- warn()
Abstract console.warn to not trigger lint warnings/errors.
Outputs the warning in yellow text.
Accepts the 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.
- webservedDirsCopy(webservedDirsFull, webservedDirsShort, staticDir)
Copy webserved dirs to static site dir.
extendButNotOverride(obj1, obj2) ⇒ object
Recursively merge properties of two objects.
Kind: global function
Returns: object
- The mutated obj1 object.
Param | Type | Description |
---|
obj1 | object | This object's properties have priority over obj2. |
obj2 | object | If obj2 has properties obj1 doesn't, add to obj1, but do not override. Since obj1 gets mutated, the return value is only necessary for the purpose of referencing to a new variable. |
regexReservedCharsEscape(regexStr) ⇒ string
Escape reserved regular expression characters.
Kind: global function
Returns: string
- A regular expression with escaped reserved characters.
Param | Type | Description |
---|
regexStr | string | The regular expression with unescaped reserved characters. |
shuffle(a) ⇒ array
Shuffle the elements of an array with the Fisher-Yates algorithm.
Kind: global function
Returns: array
- Shuffled array.
See
Param | Type | Description |
---|
a | array | Array to be shuffled. Since a gets mutated, the return value is only necessary for the purpose of referencing to a new variable. |
backendDirCheck(backendDir) ⇒ string
Validate existence of a backend subdirectory.
Kind: global function
Returns: string
- A valid absolute path to the backend subdirectory, or an empty string.
Param | Type | Description |
---|
backendDir | string | The relative path to a subdirectory of the backend. |
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: global function
Returns: string
- A normalized file extension, or an empty string if it fails validation.
Param | Type | Description |
---|
ext | string | File extension. |
findup(filename, workDir) ⇒ string
Search the file system from a starting directory upward.
Kind: global function
Returns: string
- The absolute path to the found file or an empty string if the search fails.
Param | Type | Description |
---|
filename | string | The file being searched for. |
workDir | string | The absolute path where the search starts. |
pathResolve() ⇒ 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: global function
Returns: string
- Path.
uiConfigNormalize(uiObj, workDir) ⇒ object
Normalize UI config values.
Turn relative paths into absolute paths.
Prepend leading dots to extnames if necessary.
Kind: global function
Returns: object
- The mutated uiObj.
Param | Type | Description |
---|
uiObj | object | The UI configuration object. Since uiObj gets mutated, the return value is only necessary for the purpose of referencing to a new variable. |
workDir | string | The absolute path to the directory directly above the relative paths in the uiObj. |
error()
Abstract console.error to not trigger lint warnings/errors.
Outputs the error in red text.
Accepts the same arguments as console.error.
Kind: global function
i(obj, depth, showHidden)
"i" for "inspect". Shorthand for util.inspect or console.dir.
This exists primarily for internal debugging. Be sure to remove invocations when done because they won't pass lint.
Kind: global function
Param | Type | Description |
---|
obj | object | The object to inspect. |
depth | null | number | The number of times to recurse while inspecting the object. null means infinity. |
showHidden | boolean | Whether the object's non-enumerable properties will be included in the result. |
info()
Abstract console.info to not trigger lint warnings/errors.
Outputs the info in green text.
Accepts the same arguments as console.info.
Kind: global function
log()
Abstract console.log to not trigger lint warnings/errors.
Accepts the same arguments as console.log.
Kind: global function
warn()
Abstract console.warn to not trigger lint warnings/errors.
Outputs the warning in yellow text.
Accepts the same arguments as console.warn.
Kind: global function
webservedDirnamesTruncate(webservedDirsFull) ⇒ array
Remove first path segment from values in webservedDirsFull array. Return a new array composed of these new values.
Kind: global function
Returns: array
- The webserved directories stripped of configuration prefix.
Param | Type | Description |
---|
webservedDirsFull | array | The array of webserved directories. |
Copy webserved dirs to static site dir.
Kind: global function
Param | Type | Description |
---|
webservedDirsFull | array | Path to directories webserved by Fepper. |
webservedDirsShort | array | Path to directories webserved by Fepper truncated for publishing to static site. |
staticDir | string | The destination directory. |