Comments (5)
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.
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.
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.
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.
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)
- Consider adding wordwrap from Django HOT 1
- intword() approx vs. exact HOT 1
- Move tests to GitHub Actions
- Natural Time
- "ordinal" should have a flag for spelling out 1-9 in AP style HOT 1
- Feature request: intcomma options HOT 1
- Migrate intcomma to Intl.NumberFormat HOT 2
- AP Date, but UTC HOT 6
- intword should support negative numbers HOT 1
- Should there be a tabular version of apmonth? (Jan, Mar, Nov, etc.)
- Find answer for date functions and year outputs
- Support for a precision-based round/floor/ceil function
- intcomma rounding HOT 1
- Decide whether date methods continue to be locale sensitive
- Add `yesno` function
- Add `boolify` function (working title)
- aptime gives incorrect output at noon HOT 1
- Add TypeScript definitions HOT 1
- Consider adding json_script from Django HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from journalize.