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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@knighttower/js-power-helper-functions

v1.0.4

Published

JsPowerHelperFunctions is a JavaScript class that adds extra functionality for complex functions. This class is part of a larger project and can be imported from the @knighttower/adaptive package.

Readme

Note:

For better maintenance, this library has been placed along with JsUtilities (https://github.com/knighttower/JsUtility) to create an easier entry point for many resources that will collaborate together --> only the docs will remain here for now.

Installation

npm i @knighttower/js-utility-functions
yarn add @knighttower/js-utility-functions
import PowerHelpers from '@knighttower/js-utility-functions';

In the browser

It loads as a 'window' object --> window.PowerHelpers

<script src=" https://cdn.jsdelivr.net/npm/@knighttower/js-utility-functions@latest/dist/browser/PowerHelpers.min.js"></script>

// ---> Also available as ESM, UMD, CJS, JS // ESM
<script src="https://esm.run/@knighttower/js-utility-functions@latest/index.mjs"></script>
// UMD
<script src="https://cdn.jsdelivr.net/npm/@knighttower/js-utility-functions@latest/dist/umd/PowerHelpers.min.js"></script>
// CJS
<script src="https://cdn.jsdelivr.net/npm/@knighttower/js-utility-functions@latest/dist/cjs/PowerHelpers.min.js"></script>

PowerHelper Library Documentation

This file was created as part of "adaptive.js" (https://github.com/knighttower/adaptive.js) but it can use in any project by itself due to the functionality offered by its module functions.
Find oter cool things at knighttower.io
release versionNPM published

Table of Contents


getDirectivesFromString

Note: All the above with the exception of the Id/class will be converted into actual objects

Function Signature

function getDirectivesFromString(settings: String|Array|Object): Object|void|null;

Converts strings formats into objects.

  • Function: getDirectivesFromString(settings)
  • Parameters: {String|Array|Object} settings
  • Returns: {Object|void|null}

Handles the following patterns to get an object from string attributes:

  • Matches the JSON objects as string: {'directive':{key:value}} OR {key:value}
  • Matches the Array as string: [value, value] OR ['value','value']
  • Matches a multi-array string like [[value,value]],value]
  • Matches object-style strings: directive.tablet(...values) OR directiveexpression
  • Matches string ID or class: literals Id(#) or class (.). Note that in Vue it needs to be in quotes attr="'#theId'"
  • Matches simple directive function style: directive(#idOr.Class)

Examples

getDirectivesFromString('directive.tablet(...values)'); // {directive: {tablet: 'values'}}
getDirectivesFromString('[[value,value]],value]'); // {directive: 'values', directive2: 'values'}
getDirectivesFromString('directive.tablet|mobile(...values)'); // {directive: {tablet: 'values', mobile: 'values'}}
getDirectivesFromString('directive.tablet(...values)'); // {directive: {tablet: 'values'}}

findAndReplaceInArray

Function Signature

function findAndReplaceInArray(arr: Array, find: String, value: Array|Object|String): Null|Array;

Recursively will loop in array to find the desired target.

  • Function: findAndReplaceInArray(arr, find, value)
  • Parameters: {Array} arr, {String} find, {Array|Object|String} value
  • Returns: {Null|Array}

Examples

/**
 * Recursively will loop in array to find the desired target
 * @function findAndReplaceInArray
 * @param {Array} arr
 * @param {String} find The target (needle)
 * @param {Array|Object|String} value Replacer
 * @return {Null|Array}
 * @example findAndReplaceInArray([1,2,3,4,5], 3, 'three') // [1,2,'three',4,5]
 */

getMatchInBetween

Function Signature

function getMatchInBetween(str: String, p1: String|Regex, p2: String|Regex, all: Boolean): String|Array|Null;

Find a match in between two delimeters, either string or regex given, returns clean matches.

  • Function: getMatchInBetween(str, p1, p2, all)
  • Parameters: {String} str, {String|Regex} p1, {String|Regex} p2, {Boolean} all
  • Returns: {String|Array|Null}

Examples

/**
 * find a match in between two delimeters, either string or regex given, returns clean matches
 * @function getMatchBlock
 * @param {String} str
 * @param {String|Regex} p1
 * @param {String|Regex} p2
 * @param {Boolean} all If it should return all matches or single one (default)
 * @return {String|Array|Null}
 * @example getMatchInBetween('hello world', 'h', 'd') // 'ello worl'
 * @example getMatchInBetween('hello <world/>', '<', '/>', true) // ['world']
 * @example getMatchInBetween('hello <world/>', '<', '/>') // 'world'
 */

getMatchBlock

getMatchBlock(str, p1, p2, all = false)

/**
 * Find math by delimeters returns raw matches
 * @function getMatchBlock
 * @param {String} str
 * @param {String|Regex} p1
 * @param {String|Regex} p2
 * @param {Boolean} all If it should return all matches or single one (default)
 * @return {String|Array|Void}
 * @example getMatchBlock('is a hello world today', 'h', 'd') // 'hello world'
 * @example getMatchBlock('is a hello world today', 'h', 'd', true) // ['hello world']
 * @example getMatchBlock('is a <hello world/> today', '<', '/>') // '<hello world/>'
 */

cleanStr

Clean a string from delimeters or just trimmed if no delimeters given

Function Signature

function cleanStr(str: String, p1: String|Regex, p2: String|Regex): String;

Examples

/**
 * Clean a string from delimeters or just trimmed if no delimeters given
 * @funtion cleanStr
 * @param {String} str - String to use
 * @param {String|Regex} p1 - Delimeter 1
 * @param {String|Regex} p2 - Delimeter 2
 * @return {String}
 * @example cleanStr('hello world', 'h', 'd') // 'ello worl'
 * @example cleanStr('  hello world  ') // 'hello world'
 * @example cleanStr('hello world', 'hello') // 'world'
 * @example cleanStr('Hello World. Sunshine is here!', '\..*!') // Hello World
 * @example cleanStr('Hello World. Sunshine is here!', /Hello/g) // ' World. Sunshine is here!'
 * @example cleanStr('Hello World. Sunshine is here!', /Hello/g, /Sunshine/g) // ' World.  is here!'
 */

setExpString

Scapes a string to create a regex or returns the regex if it already is an expression

setExpString(exp)

/**
 * Scapes a string to create a regex or returns the regex if it already is an expression
 * @function setExpString
 * @param {String|Regex} exp
 * @return {String|Regex}
 * @example setExpString('hello') // '\h\e\l\l\o'
 * @example setExpString(/hello/) // /hello/
 * @example setExpString([hello]) // \\[hello\\/ then use like new new RegExp(setExpString(StringOrRegex))
 */

setLookUpExp

Regex builder to get a match in between two delimeters

setLookUpExp(p1, p2)

/**
 * Regex builder to get a match in between two delimeters
 * @function setLookUpExp
 * @param {String|Regex} p1 - Delimeter 1
 * @param {String|Regex} p2 - Delimeter 2
 * @return {String} - Regex
 * @example setLookUpExp('h', 'd') // 'h((.|\n)*?)d'
 * @usage:
 * const pattern = setLookUpExp(".", "!");
const regex = new RegExp(pattern, 'g');
const text = "Hello World. Sunshine is here! Have fun!";
const matches = text.match(regex);
console.log(matches);  // Output: [". Sunshine is here!"]
 */

removeQuotes

Function Signature

function removeQuotes(str: String): String;

Examples

/**
 * Remove quotes from a string
 * @function removeQuotes
 * @param {String} str
 * @return {String}
 * @example removeQuotes('"hello"') // hello
 * @example removeQuotes("'hello'") // hello
 */

fixQuotes

/**
 * Fix quotes from a string
 * @function fixQuotes
 * @param {String} str
 * @return {String}
 * @example fixQuotes("'hello'") // "hello"
 * @example fixQuotes('"hello"') // "hello"
 */

addQuotes

/**
 * Add quotes to a string
 * @function addQuotes
 * @param {String} str
 * @return {String}
 * @example addQuotes('hello') // "hello"
 */