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

@brendanatme/utils

v2.2.1

Published

JS/TS helper methods

Downloads

3

Readme

Utils

JS/TS functional helper methods, no external dependencies.

Usage

Import Package

Import the entire package:

import * as utils from '@brendanatme/utils';

or import individual methods:

camelCase

import camelCase from '@brendanatme/utils/camel-case';

camelCase('my-utils'); // 'myUtils'

capitalize

import capitalize from '@brendanatme/utils/capitalize';

capitalize('my utils'); // 'My Utils'

classCase

import classCase from '@brendanatme/utils/class-case';

classCase('my-utils'); // 'MyUtils'

contains

import contains from '@brendanatme/utils/contains';

contains('dank')(['dank', 'memes']); // true

// or

const containsDank = contains('dank');

containsDank(['dank', 'memes']); // true

containsAny

import containsAny from '@brendanatme/utils/contains-any';

containsAny('dank', 'bank', 'jank', 'plank')(['dank', 'memes']); // true

// or

const containsRhymesWithDank = contains('dank', 'bank', 'jank', 'plank');

containsRhymesWithDank(['dank', 'memes']); // true

decorate

import decorate from '@brendanatme/utils/decorate';

const decorated = decorate(
  myHoc1,
  myHoc2,
  myHoc3,
)(MyComponent); // DecoratedComponent

doOnce

import doOnce from '@brendanatme/utils/do-once';

let i = 0;
const once = doOnce((n) => { i = i + n; });
[1, 2, 3].map((_i) => once(_i)); // i === 1

handleize

import handleize from '@brendanatme/utils/handleize';

handleize('No_$strange_Chars ALLOWED'); // 'no-strange-chars-allowed'

invertObject

import invertObject from '@brendanatme/utils/invert-object';

invertObject({ foo: 'bar' }); // { bar: 'foo' }

mapArrayToObject

import mapArrayToObject from '@brendanatme/utils/map-array-to-object';

mapArrayToObject('name')([
  { name: "Ryu", rank: 1 },
  { name: "Zangief", rank: "Too powerful to rank" },
]); // { Ryu: { name, rank }, Zangief: { name, rank } }

mapStringToObject

import mapStringToObject from '@brendanatme/utils/map-string-to-object';

mapStringToObject()('foo:bar,a:b'); // { foo: 'bar', a: 'b' }

// or

const customMap = mapStringToObject(';', '=');

customMap('foo=bar;a=b'); // { foo: 'bar', a: 'b' }

mergeArrays

import mergeArrays from '@brendanatme/utils/merge-arrays';

mergeArrays(['how', 'do'], ['you'], ['do', '?']); // ['how', 'do', 'you' 'do', '?']

singularize

import singularize from '@brendanatme/utils/singularize';

singularize('MurderousParakeets'); // 'MurderousParakeet'

splitArray

import splitArray from '@brendanatme/utils/split-array';

const catalog = [
  {
    category: 'Books',
    title: 'Pillars of the Earth',
  },
  {
    category: 'Movies',
    title: 'The Prestige',
  },
]

splitArray((item) => item.category)(catalog); // { Movies: [...], Books: [...] }

// or

const splitByCategory = splitArray((item) => item.category);

splitByCategory(catalog); // { Movies: [...], Books: [...] }

timer

import * as timer from '@brendanatme/utils/timer';

const myJobId = 'The Job Im Running';

// optional: set log function (defaults to console.log)
timer.setLogFn((...msgs) => console.warn(...msgs));

// begins timer and logs message
timer.start(myJobId); // --> "Timer: begin execution of 'The Job Im Running'"

// ... perform task ...

// logs length of execution time in MS:
timer.stop(myJobId); // --> "Timer: execution of 'The Job Im Running' took 5146ms"

transformKeys

import transformKeys from '@brendanatme/utils/transform-keys';

const input = { foo: 'bar' };

transformKeys((key) => `test_${key}`)(input); // { test_foo: 'bar' }

// or 

const makeTestProps = transformKeys((key) => `test_${key}`);

makeTestProps(input); // { test_foo: 'bar' }

//

wait

import wait from '@brendanatme/utils/wait';

wait(2) // waits 2 seconds
  .then(() => {}); // ... do stuff ...

// or

const init = async () => {
  const proceed = await wait(10); // waits 10 seconds

  if (proceed) {
    // ... do stuff ...
  }
};