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

helpers-ts

v1.2.2

Published

Some simple Helpers to manipulate strings and arrays for JavaScript and Typescript.

Downloads

8

Readme

helpers-ts

Latest Version Licence GitHub Tests Action Status GitHub Prettier Action Status

Downloads

Some simple Helpers to manipulate strings and arrays for JavaScript and Typescript.

If you like this package you can Buy me a Coffee ☕️

Table of contents

Installation

# To install this package, run:
$ npm install helpers-ts
# or
$ npm i helpers-ts

Usage

This package is intended to help you manipulate strings and arrays, in JavaScript and Typescript. It is available from the NPM Registry.

import { toCamel } from 'helpers-ts'

const str = 'Hello world'
console.log(toCamel(str))

// Output: 'helloWorld'

Strings

slugify()

Converts a string into slug.

slugify('Hello world') // 'hello_world'
slugify('Hello world', '-') // 'hello-world'

toCamel()

Converts a string into camelCase.

toCamel('Hello world') // 'helloWorld'

toPascal()

Converts a string into PascalCase.

slugify('Hello world') // 'HelloWorld'

isUuid()

Checks if a string is a valid uuid.

isUuid('5c5a300f-20fb-416f-b026-6f53f8bdc7f5') // true
isUuid('not-uuid') // false

uuid()

Returns a random and unique Uuid.

uuid() // '5c5a300f-20fb-416f-b026-6f53f8bdc7f5'

limitStr()

Limits a string to a specified number of characters.

limitStr('This is a long string that needs to be limited.', 20)
// 'This is a long strin...'

randomStr()

Returns a random string with a specified number of characters.

randomStr(6) // 'ab12c3'

replaceStr()

Replaces occurrences of a string by another.

replaceStr('world', 'earth', 'Hello world') // 'Hello earth'

squish()

Trims and removes extra spaces between words with a specified number of space.

squish(' Hello     world ', 5) // 'Hello world'

contains()

Checks if a word is in a string.

contains('world', 'Hello world') // true
contains('earth', 'Hello world') // false

containsAll()

Check if many words are in a string.

containsAll(['string', 'test'], 'This is a string to test.') // true
containsAll(['number', 'test'], 'This is a string to test.') // false

Arrays

crossJoin()

Joins arrays and returns all possible combinations of input arrays.

You can pass more than 2 arrays.

crossJoin(['red', 'green'], ['small', 'medium'])
// [['red', 'small'], ['red','medium'], ['green', 'small'], ['green','medium']]

keyExists()

Checks if a key exists in an array.

keyExists('foo', ['foo', 'bar', 'baz']) // true
keyExists('qux', ['foo', 'bar', 'baz']) // false

keyExists('foo', { foo: 'bar', baz: 'qux' }) // true

firstKey(), lastKey()

Returns first or last key.

firstKey(['foo', 'bar', 'baz']) // 'foo'
lastKey(['foo', 'bar', 'baz']) // 'baz'

implode()

Converts an array into string.

implode(['Foo', 'Bar']) // 'Foo Bar'
implode(['Foo', 'Bar'], ', ') // 'Foo, Bar'

explode()

Converts a string into array.

explode('Foo,Bar') // ['Foo', 'Bar']
implode('Foo Bar', ' ') // ['Foo', 'Bar']

isEmpty()

Checks if an array is empty.

isEmpty([]) // true
isEmpty([1, 2, 3]) // false

shuffle()

Shuffles array keys.

shuffle([1, 2, 3, 4]) // [3, 1, 4, 2]

Numbers

randBetween

Returns a random number between min and max.

randBetween(5, 10) // 8

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

If you are interested in this project and want to improve it, fix errors or bugs, you're welcome to contribute.

Contributors

Credits

Licence

The MIT License (MIT).

Please see License File for more information.