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

qtools-functional-library

v2.0.1

Published

Useful additions to JS prototypes to facilliate chainable, functional (mostly) style. Also make life more convenient."

Downloads

46

Readme

qtools-functional-library

This is a collection of tools that allow chained operations on various Javascript datatypes.

In each case, the primary operand is this. In most cases, the function takes an argument with parameters to guide the operation.

Everything else remains compatible.

EG,

const qt=require('qtools-functional-library');

qt.help(); // this information and more

const demo=({a:{b:"Hi from b"}})

const one=demo
    .qtGetSurePath('a.b')
    .qtDump();//produces 'Hi from b [thisFilename.js]'

console.log(one); //produces '[object Object]'

Version 2:

qtPassThrough no longer always returns the inbound 'this'. If the supplied function returns a value, that is passed on. This way, any ad hoc function can affect the result chain.

Version 2.0.1 9/23/24 - removed deep clone in favor of spread operator (which didn't exist when this was written). Should have no effect on functionality.

EG,

'xxx'
    .qtPassThrough(item=>item.toUpperCase())
    .qtDump(); // -> 'XXX'

Non-chain utilities:

  • qt.help: Shows this information and more.
  • qt.log: Writes log entry with suffix identifying the file that generated the output. (See qtLog below for chained version.)

Get/Set values from an Array:

  • qtGetByProperty: Operates on an array of objects. Retrieves one or more elements based on the value of an object property specified by a dotted path.

  • qtPop: Pops the last value off an array. If a default is supplied and there is nothing left on the list, that will be returned. Really good for ArrayOfObjects.qtPop({}).

  • qtPush: Pushes a value onto an array and returns the array (unlike normal .push() which returns the length of the array)

  • qtLast: Delivers the element that would have been pop'd but does not change the array. Default if none exists.

  • qtFirst: Delivers the element zero if it exists but does not change the array. Default if none exists.

  • qtIncludesRegex: Operations on a simple array of strings. Retrieves one or more elements based on an regEx match.

Get/Set values in an Object (or array of Objects)

  • qtGetSurePath: Gets the value of a property based on a dotted string path. No crash if intermediate elements are missing. Provides default. Predates and is prettier to use than optional chaining and supports setting the value.

  • qtSetSurePath Sets the value of a property based on a dotted string path. Creates intermediate elements if they are missing.

  • qtSelectProperties: Given an Object and an Array of Strings, filters the properties into a new Object with defaults "[{}].qtSelectProperties(outFileDefinition, {moreDefaultValues:{Value:"xxx"}}))" for missing elements. Does the same for an Array of Objects.

  • qtMapProperties: Given an Object and a one level Object whose properties are functions, applies each function to the corresponding element. Does the same for an array of Objects.

Array/Object Conversions:

  • qtClone: Does a deep clone of an object or array.- qtNumberKeysToArray: Converts an object with properties that are numbers to an array, including subordinate properties.

  • qtToKeyValueArray: Converts an object to an array of objects of the form, ie, {["1"]:'one', ["2"]:'two'} => ['one', 'two']

  • qtMerge: Deep merge of two objects including array propterties.

  • qtToString: Joins an array with prefix, suffix and separator. Pretty much the same as .join().

Array/Object Template Replacement:

  • qtTemplateReplace: Takes Object and a <!template!> String ()either can be 'this' or the argument). Substitutes from the object properties into the string. If the 'this' is an array of Objects, it does it to all of them.

Output:

  • qtDump: Prints 'this' and returns it. Good for debugging complicated chains.

  • qtLog: Logs message by applying 'this' into the argument which is a string. Appends calling file name.

Misc:

  • qtPassThrough: Sits in a declarative chain and executes an arbitrary function. Returns function result if not undefined, 'this' otherwise. 'this' is available to the function.

  • qtIterate: Operates on a number. EG, (5).qtStart(7).qtIncrement(3).qtIterate(item=>item*100)

Output:

1.1.16 - fixed bug where intermediate path element could be undefined and cause a crash.

Other Cool Qtools

qtools-asynchronous-pipe-plus qtools-config-file-processor qtools-format-columns qtools-functional-library qtools-object-flattener qtools-parse-command-line qtools-secure-container qtools-template-replace-for-files qtools-transform-text