1. nth
The nth package simply takes a number and returns the same number with the appropriate placing string. For example the number 1 becomes 1st, and the number 2 becomes 2nd.
nth
Package: nth
Created by: mitchdenny
Last modified: Wed, 22 Jun 2022 12:12:23 GMT
Version: 1.1.0
License: Apache-2.0
Downloads: 95
Repository: https://github.com/mitchdenny/nth

Install

npm install nth
yarn add nth

nth

The 'nth' package contains a dirt simple module that takes an integer and then appends the appropriate place suffix. For example:

  • 1 becomes 1st
  • 2 becomes 2nd
  • 3 becomes 3rd
  • 4 becomes 4th
  • 13 becomes 13th
  • 23 becomes 23rd

Usage

Using the package is very easy. Just download it and install it via NPM:

 npm install nth --save

Once the package is downloaded and installed, you just need to require in the module and call the appendSuffix method:

 var nth = require('nth');
var output = nth.appendSuffix(23);
console.log(output); // outputs: '23rd'

If you just want to get the suffix itself (without the number) then you can call the getSuffix method.

 var nth = require('nth');
var output = nth.getSuffix(23);
console.log(output); // outputs: 'rd'

Contributions

If you find a bug feel free to submit a pull request.

Known Limitations

Beyond the few obvious test cases I haven't spend any time on more complex scenarios like dealing with exponents. I can't imagine many folks really using this library in that context anyway :)

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin