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

1.0.14 • Public • Published

usual_fn

Commonly used functions

Features

  • formatDate: Format the date in the local format of your choice
  • formatPhone : Format the phone number with/without prefix
  • formatPrice : Format the amount in human readable format

Installation

npm i usual_fn

formatDate

Format the date in the local format of your choice

formatDate(options: FormatDateOptions): string

interface FormatDateOptions {
  data: string | Date | number;
  $locale?: string;
  $t?: (arg: string) => string;
  key?: string;
}
// Example

import { formatDate } from "usual_fn";

const formattedDate = formatDate({
  data: new Date(),
});

const formattedNow = formatDate({
  data: Date.now(),
});

console.log(formattedDate);
console.log(formattedNow);

formatPhone

Format the phone number with/without prefix

formatPhoneWithPrefixe(params: FormatPhone): string

formatPhone(params: FormatPhone): string

interface FormatPhone {
  data: string;
}
// Example

import { formatPhone, formatPhoneWithPrefixe } from "usual_fn";

const formattedPhoneWithPrefix = formatPhoneWithPrefixe({
  data: "22997000000",
});
const formattedPhone = formatPhone({
  data: "97000000",
});

console.log(formatedPhoneWithPrefix);
console.log(formatedPhone);

formatPrice

Format the amount in human readable format

formatPrice(params: FormatPrice): string

interface FormatPrice {
  amount: string | number;
  currency?: Boolean;
  device?: string;
}
// Example

import { formatPrice } from "usual_fn";

const amount = formatPrice({
  amount: 10000000,
  currency: true,
  device: "F CFA",
});

console.log(amount);

Readme

Keywords

none

Package Sidebar

Install

npm i usual_fn

Weekly Downloads

6

Version

1.0.14

License

ISC

Unpacked Size

4.47 kB

Total Files

10

Last publish

Collaborators

  • florisse