npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fepper-utils

v1.4.7

Published

Fepper utilities

Downloads

144

Readme

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).

| Param | Type | Description | | --- | --- | --- | | key | string | The 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.

| Param | Type | Description | | --- | --- | --- | | extendedTemplate | string | The 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.

| Param | Type | Description | | --- | --- | --- | | obj | object | The object from which to get the data. | | path | string | array | Dot-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.

| Param | Type | Description | | --- | --- | --- | | ...objects | object | The 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.

| 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: exported function
Returns: array - Shuffled array.
See

  • https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array
  • https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
  • https://github.com/e2tha-e/js-shuffle-algorithms

| 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. |

strReplaceGlobal(haystack, needle, replacement) ⇒ string

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

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

| Param | Type | Description | | --- | --- | --- | | haystack | string | Full string to be modified. | | needle | string | The substring to be replaced. | | replacement | string | The 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.

| Param | Type | Description | | --- | --- | --- | | backendDir | string | The path to a subdirectory of the backend. |

rmRfFilesNotDirs(dirToEmpty)

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

Kind: exported function

| Param | Type | Description | | --- | --- | --- | | dirToEmpty | string | Directory 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.

| Param | Type | Description | | --- | --- | --- | | ext | string | File 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.

| Param | Type | Description | | --- | --- | --- | | filename | string | The file being searched for. | | workDir | string | The 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.

| Param | Type | Description | | --- | --- | --- | | ...pathSegments | string | Path 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.

| 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. | | [appDir] | string | The 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

| Param | Type | Description | | --- | --- | --- | | ...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

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | object | | The object to inspect. | | [depth] | null | number | null | Number of times to recurse while inspecting the object. null means infinity. | | [showHidden] | boolean | false | Whether 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

| Param | Type | Description | | --- | --- | --- | | ...args | * | Same arguments as console.info. |

log(...args)

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

Kind: exported function

| Param | Type | Description | | --- | --- | --- | | ...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

| Param | Type | Description | | --- | --- | --- | | ...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.

| Param | Type | Description | | --- | --- | --- | | webservedDirsFull | array | The array of webserved directories. |

webservedDirsCopy(webservedDirsFull, webservedDirsShort, staticDir)

Copy webserved dirs to static site dir.

Kind: exported 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. |