general-formatter
TypeScript icon, indicating that this package has built-in type declarations

0.0.16 • Public • Published

general-formatter

general-formatter

Description

This is a small npm package, with a few functions that I use very often. I got tired of having to code it many different projects :)

The functions a very straightforward. I'm using the Intl object from JavaScript that provides language sensitive string comparison, number formatting, and date-time formatting. Check the official MDN docs here JS Intl

Disclaimer

This is my first ever npm package, so if you have any suggestions or a better solution you are more than welcome to contribute to this project. Or if you want to keep adding more formatting or format validation functions :). But please let's keep it simple.

Installation

Fork this repository, and follow the git commands bellow:

cd <YourProjectName>
npm i general-formatter

How to use?

general-formatter uses ES6 so you need to use imports :)

import {convertToMoneyString, convertToDateString, validateEmailFormat} from "general-formatter"

Sample Functions

convertToMoneyString

This function takes a number amount, string country code, the style you want the number to be returned to, and the currency code

const myMoneyString = convertToMoneyString(29.465654023, "en-US", "currency", "USD")

console.log(myMoneyString) // Logs $29.47

convertToDateString

This function takes a date-like string, and a country code string referring to the country date format you want your date to be returned.

const myDateString = convertToDateString("2022-10-10T22:11:02.024+00:00", "en-US")

console.log(myDateString) // Logs 10/10/2022

validateEmailFormat

This function takes an string, and uses regex to validate if the string has a valid email format.

const isValidEmail = validateEmailFormat("johndoe")

console.log(isValidEmail) // Logs false

How to contribute

  • Fork this repository
  • Follow the git commands in your favorite terminal
    git clone git@github.com:<gitHubUsername>/formatter-npm-package.git
    cd formatter-npm-package
    git checkout -b <NameYourNewBranch>
  • After adding your changes please commit the new branch and open a PR
    git add <YourChanges>
    git commit -m <Your changes comments>
    git push origin <Your branch name>
  • Pull Request in GitHub Pull Request

Readme

Keywords

Package Sidebar

Install

npm i general-formatter

Weekly Downloads

0

Version

0.0.16

License

MIT

Unpacked Size

6.52 kB

Total Files

6

Last publish

Collaborators

  • anthgrim