0.8.3 • Published 7 months ago

ordinalify v0.8.3

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

Ordinalify

npm version

license

Ordinalify is a package used to get number ordinals in javascript apps.

Ordinals: are grammatical or numerical indicators that express the position or order of items in a series, such as "1st" for first, "2nd" for second, and so on.

Installation

Install the package using npm:

npm install ordinalify

Install the package using yarn:

yarn add ordinalify

Usage

Here's a basic example of how to use ordinalify:

Word Ordinals e.g("First", "Second", "Third", "Fourth"):

import { WordOrdinal } from "ordinalify";

const numberRange = Array.from({ length: 4 }, (_, index) => index + 1);

numberRange.map((number) =>
	console.log(WordOrdinal(number, { capitalizeFirstLetter: true }))
);

Number Ordinals e.g ("1ST", "2ND", "3RD", "4TH"):

import { NumberOrdinal } from "ordinalify";

const numberRange = Array.from({ length: 4 }, (_, index) => index + 1);

numberRange.map((number) =>
	console.log(NumberOrdinal(number, { capitalize: true }))
);

API (Parameters)

WordOrdinal

The WordOrdinal function/component is responsible for converting numbers into their ordinal form in word form e.g "Fifth", "Twenty-Nine".

Props:

  • number (required): The number to be converted into an ordinal form.
  • options (optional): An object containing the following properties:
    • capitalizeFirstLetter (optional): A boolean indicating whether the result should be in title case format. This can be used as the second parameter using node or the second prop with the name options and the key value name "capitalizeFirstLetter"

Example: Word Ordinal("first", "second", "third")

In Node:

const { WordOrdinal } = require("ordinalify");

const numberRange = Array.from({ length: 3 }, (_, index) => index + 1);
numberRange.map((number) => console.log(WordOrdinal(number)));

In React:

import React from "react";
import { WordOrdinal } from "ordinalify/dist/react";

const App = () => {
	const numberRange = Array.from({ length: 3 }, (_, index) => index + 1);
	return (
		<section>
			{numberRange.map((number, index) => (
				<WordOrdinal
					key={index}
					number={number}
					options={{ capitalizeFirstLetter: true }}
				/>
			))}
		</section>
	);
};

export default App;

NumberOrdinal

The NumberOrdinal function/component is responsible for converting numbers into their ordinal form in number form e.g "5TH", "29TH".

Props:

  • number (required): The number to be converted into an ordinal form.
  • options (optional): An object containing the following properties:
    • capitalize (optional): A boolean indicating whether the result should be in title case format. This can be used as the second parameter using node or the second prop with the name options and the key value name "capitalizeFirstLetter"
    • lowercase (optional): A boolean indicating whether the result should be in lowercase format.
    • subscript (optional): A boolean indicating whether the result should be in subscript format. (Note: Subscript does not work in Node environment)
    • superscript (optional): A boolean indicating whether the result should be in superscript format. (Note: Superscript does not work in Node environment)

Example: Number Ordinal ("1ST", "2ND", "3RD")

In Node

const { NumberOrdinal } = require("ordinalify");

const numberRange = Array.from({ length: 3 }, (_, index) => index + 1);
numberRange.map((number) =>
	console.log(NumberOrdinal(number, { capitalize: true }))
);

In React

import React from "react";
import { NumberOrdinal } from "ordinalify/dist/react";

const App = () => {
	const numberRange = Array.from({ length: 3 }, (_, index) => index + 1);
	return (
		<section>
			{numberRange.map((number) => (
				<NumberOrdinal
					number={number}
					options={{ capitalize: true }}
				/>
			))}
		</section>
	);
};

export default App;

Contributing

This Markdown document is well-structured and provides clear instructions for using the ordinalify package. If you have any specific concerns or requests, feel free to let me know!

0.8.3

7 months ago

0.8.2

7 months ago

0.8.1

7 months ago

0.8.0

7 months ago

0.7.8

7 months ago

0.7.7

7 months ago

0.7.6

8 months ago

0.7.5

8 months ago

0.7.4

8 months ago

0.7.3

8 months ago

0.7.2

8 months ago

0.7.1

8 months ago

0.7.0

8 months ago

0.6.0

8 months ago

0.5.0

8 months ago

0.4.1

8 months ago

0.3.1

8 months ago