Giter Club home page Giter Club logo

Comments (5)

rdmurphy avatar rdmurphy commented on June 19, 2024 1

Hah yeah know what you mean! 😅

I gave it a pass and honestly I think it's fine! This isn't really adding all that many extra bytes other than the additional export of ordinalsuffix. I didn't add much new code to pull it off — I extracted the suffix stuff out of ordinal and now ordinal uses ordinalsuffix internally.

from journalize.

sawyerclick avatar sawyerclick commented on June 19, 2024

It would also involve some logic to check that spellOutOrdinals and onlySuffix are not simultaneously true. With the example code above, though, spellOutOrdinals takes precedence, as it is originally written.

from journalize.

rdmurphy avatar rdmurphy commented on June 19, 2024

Hey @sawyerclick — I think this is a great idea!

For better or worse I've been pretty consistent about not having the methods of journalize have extra parameters and I would like to keep it that way if possible. What do you think about instead adding this functionality as a new function? Perhaps journalize.ordinalsuffix()?

Then we could make ordinal use that for its suffix logic and surface both paths without a breaking change.

from journalize.

sawyerclick avatar sawyerclick commented on June 19, 2024

That works swell! I'm happy to take the first bite at creating this, unless you have a hankering for it.

ordinalSuffix would reuse the same arrays you have up top, so we could move those to a shared file. I see the final being something like this, following a lot of the smart logic in the original:

// `ordinals` here represents an object in
// which we can store the shared arrays/logic
// between ordinal and ordinalSuffix
import { isInteger, isNil, ordinals } from './utils';

export default function ordinalSuffix(val) {
  // if `val` is undefined or null, return an empty string
  if (isNil(val)) return '';

  const convertedVal = +val;

  // if `convertedVal` is not an integer, return `val`
  if (!isInteger(convertedVal)) return '';

  // if `convertedVal` is 11, 12 or 13, English gets weird
  if (ENGLISH_ORDINAL_EXCEPTIONS.indexOf(convertedVal % 100) > -1) {
    return SUFFIXES[0];
  }

  return SUFFIXES[convertedVal % 10];
}

from journalize.

sawyerclick avatar sawyerclick commented on June 19, 2024

After some thought, I wonder if it's worth the extra bytes in being its own function or existing outside of ordinal.js. The suffix can essentially be accessed via ordinal(12).slice(-2), and the param was merely a convenience. I'm torn between "yes! this should exist to make it easier" and "no! that's convenience at the sake of bloat and overhead. something native exists!"

from journalize.

Related Issues (20)

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.