Giter VIP home page Giter VIP logo

tinyplural's Introduction

✍ tinyplural

bundlephobia npm version Run Jest Tests CodeQL

A tiny pluralizer for English nouns

tinyplural is an easy to use utility function that converts your strings into their relevant plurals dynamically. Comes with 0 dependencies.

Demo

import tinyplural from 'tinyplural';

const formattedDate = tinyplural('day', 2);

return (
  <>
    <p>Next payment due in {formattedDate}</p>
  </>
);

// => Next payment due in 2 days

It's fully written in TypeScript, with a test-suite to go with it.

The library is available as an npm package. To install the package run:

npm install tinyplural --save
# or with yarn
yarn add tinyplural

Want to get involved! Read our Contributors' Guide for details.

Found a bug or a rule that doesn't work? Open a bug report ticket.

Got a feature to add? Fork the repo, add your changes, and make a pull request.

Info

Say you need to present a promocode that ends in a number of days. Using tinyplural, you can just give the singular noun and the value and it will return the correct plural version.

Noun Plural
day days
hero heroes
goose geese
fish fish

Resources

These are some good guides explaining the rules behind plural nouns in English:

tinyplural's People

Contributors

kwaimind avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

tinyplural's Issues

[BUG] endsInIs and endsInUs is the same func

These are the same functions so can be combined into one and reused.

Thinking of using an array of objects with options

const functions = [
  isIregular,
  isNonChanging,
  endsInO,
  endsInY,
  endsInFOrFe,
  {
    action: endsInIs,
    findKey: 'is',
    endKey: 'es',
  },
  schshxzNoun,
  endsInUs,
];

[BUG] Noun casing is not supported

Describe the bug
If a user passes in a noun like "mAn", how should we return the plural? Just by removing it or try and reapply the casing?

[FEATURE] Rename package

MakeSuffix isn’t the best name. Should be updated to tiny-plural or tiny-suffix if we want to cover more suffix cases.

TypeScript code review

This is my first real attempt at a TypeScript project. It would be amazing to get some more experienced eyes to take a look at what I've made so far.

Add more unit tests

Right now the unit tests are basic and could do with being more detailed.

It would be great to get more tests added to the sub-functions as well as the main makeSuffix function. This will help us find potential bugs and issues I've missed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.