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

@rypen-dev/helpers

v1.0.24

Published

Javascript utilities for Rypen projects.

Downloads

132

Readme

@rypen-dev/helpers

npm (scoped) npm bundle size (minified)

Javascript helpers for rypen projects.

Install

$ npm install @rypen-dev/helpers

Helper methods

Credit card

import { creditCard } from "@rypen-dev/helpers";

creditCard.formatCreditCardType('MasterCard'); // 'MasterCard'
creditCard.formatCreditCardType('AmericanExpress'); // 'AMEX'

creditCard.formatMaskedCreditCard('XXXX1234'); // '**** 1234'

Currency

import { currency } from "@rypen-dev/helpers";

currency(1234.56); // '$1,234.56'

Error processing

A wrapper around displaying errors from api requests that culls out the error message.

import { processError } from "@rypen-dev/helpers";

const serviceErrorResponse = {
    data: {
        ErrorMessage: 'The request was invalid.',
        ...
    }
}

processError(serviceErrorResponse); // 'The request was invalid.'

Object manipulation

Mostly used to lookup enum keys by value, and to prettify the enum.

import { getKeyByValue, transformEnumForDisplay } from "@rypen-dev/helpers";

const testEnumObject = {
    FIRST_VALUE: 0,
    SECOND_VALUE: 1,
}

getKeyByValue(0); // 'FIRST_VALUE'
transformEnumForDisplay(0); // 'First Value'

Querystring reading

import { querystring } from "@rypen-dev/helpers";

// rypen.com/test?id=123
querystring('id'); // '123'

// rypen.com/test?id=123&value=something
querystring('value'); // 'something'
querystring('anotherthing'); // false

Scroll To

Animated scroll to position or element. Takes in an HTML element, selector string, or position number. Default duration is 500ms. Default offset is 0.

import { scroll } from "@rypen-dev/helpers";

// scroll([element, selector or position], [duration], [offset])
scroll(document.getElementById('#element-to-scroll-to'), 500); // scroll to element's position
scroll('#element-to-scroll-to', 1000, 200); // scroll to element's position plus 200px
scroll(1539, 2000); // scroll to exact position

Validation

Validation helpers. Method | Description | Parameters --- | --- | --- empty | Check whether input is empty, can be used on string, number, array, and object types. Option to count 0 as non-empty. | value: [any], zeroIsNotEmpty: bool (default false) validEmail | Basic validation for a valid email address. | email: string validZip | Validation for US and Canadian postal codes. | zip: string, canadian: bool (default false) validPhone | Validation for US phone numbers. | phone: string validCardNumber | Validation for credit card numbers, uses the Luhn Check | card: string validCardCode | Validation for credit card code number. | code: string validExpirationDate | Validation for credit card expiration date (valid date and not in past). | dateString: string (format ####, e.g. 0122)


import { validation } from "@rypen-dev/helpers";

// empty
validation.empty(''); // true
validation.empty(0); // true
validation.empty('   '); // true
validation.empty([]); // true
validation.empty('foo'); // false
validation.empty(0, true); // false

// validEmail
validation.validEmail('gibberish'); // false
validation.validEmail('[email protected]'); //true

// validZip
validation.validZip('55512'); // true
validation.validZip('123'); // false
validation.validZip('C4N1X3'); // false
validation.validZip('C4N1X3', true); // true

// validPhone
validation.validPhone('6125551234'); // true
validation.validPhone('xxx123'); // false

// validCardNumber
validation.validCardNumber('bar'); // false

// validCardCode
validation.validCardCode('12'); // false
validation.validCardCode('123'); // true
validation.validCardCode('1234'); // true

// validExpirationDate
validation.validExpirationDate('0126'); // true
validation.validExpirationDate('0199'); // false
validation.validExpirationDate('foo'); // false