Skip to content

Commit 5c5607f

Browse files
committed
Clean up
1 parent 2d95aa9 commit 5c5607f

13 files changed

+104
-44
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Node CI
33
on: [push, pull_request]
44

55
env:
6-
CI: "true"
6+
CI: 'true'
77

88
jobs:
99
test:
@@ -28,7 +28,7 @@ jobs:
2828
uses: coverallsapp/[email protected]
2929
with:
3030
github-token: ${{ secrets.GITHUB_TOKEN }}
31-
parallel: "true"
31+
parallel: 'true'
3232
# coverage_complete:
3333
# runs-on: ubuntu-latest
3434
# needs:

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
coverage
12
dist
23
package.json
34
package-lock.json

__tests__/apnumber.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import apnumber from '../src/apnumber';
22

33
describe('apnumber', () => {
44
it('should correctly convert numbers', () => {
5-
const testList = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n =>
5+
const testList = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((n) =>
66
n.toString()
77
);
88

__tests__/ordinal.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ describe('ordinal', () => {
77
'2',
88
'3',
99
'4',
10+
'9',
11+
'10',
1012
'11',
1113
'12',
1214
'13',
@@ -20,6 +22,23 @@ describe('ordinal', () => {
2022
'2nd',
2123
'3rd',
2224
'4th',
25+
'9th',
26+
'10th',
27+
'11th',
28+
'12th',
29+
'13th',
30+
'101st',
31+
'102nd',
32+
'103rd',
33+
'111th',
34+
];
35+
const spelledOutOrdinalResultList = [
36+
'first',
37+
'second',
38+
'third',
39+
'fourth',
40+
'ninth',
41+
'10th',
2342
'11th',
2443
'12th',
2544
'13th',
@@ -32,6 +51,10 @@ describe('ordinal', () => {
3251
testList.forEach((n, idx) => {
3352
expect(ordinal(n)).toBe(resultList[idx]);
3453
});
54+
55+
testList.forEach((n, idx) => {
56+
expect(ordinal(n, true)).toBe(spelledOutOrdinalResultList[idx]);
57+
});
3558
});
3659

3760
it('should return empty string when input is `undefined`', () => {

package-lock.json

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,16 @@
4545
"homepage": "https://github.com/rdmurphy/journalize#readme",
4646
"devDependencies": {
4747
"@babel/preset-env": "^7.3.4",
48+
"@newswire/prettier-config": "^3.0.0",
49+
"@types/jest": "^25.2.1",
4850
"@zeit/git-hooks": "^0.1.4",
49-
"coveralls": "^3.0.3",
51+
"coveralls": "^3.0.13",
5052
"documentation": "^12.0.0",
5153
"jest": "^25.1.0",
5254
"microbundle": "^0.11.0",
5355
"precise-commits": "^1.0.2",
54-
"prettier": "^1.16.4"
56+
"prettier": "^2.0.5"
5557
},
5658
"dependencies": {},
57-
"prettier": {
58-
"bracketSpacing": true,
59-
"printWidth": 80,
60-
"semi": true,
61-
"singleQuote": true,
62-
"tabWidth": 2,
63-
"trailingComma": "es5"
64-
}
59+
"prettier": "@newswire/prettier-config"
6560
}

src/apmonth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* JavaScript's life choices. Exported for testing purposes.
44
*
55
* @private
6-
* @type {Object}
6+
* @type {object}
77
*/
88
export const AP_MONTHS = {
99
0: 'Jan.',

src/apnumber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isInteger, isNil } from './utils';
33
/**
44
* List of spelled out numbers per AP style.
55
* @private
6-
* @type {Array}
6+
* @type {string[]}
77
*/
88
const AP_NUMBERS = [
99
'one',

src/intword.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isInteger, isNil } from './utils';
33
/**
44
* Array of suffixes to be used by intword.
55
* @private
6-
* @type {Array}
6+
* @type {string[]}
77
*/
88
const SUFFIXES = [
99
'million',

src/ordinal.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,42 @@ import { isInteger, isNil } from './utils';
33
/**
44
* A list of suffixes for conversions.
55
* @private
6-
* @type {Array}
6+
* @type {string[]}
77
*/
88
const SUFFIXES = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th'];
99

10+
/**
11+
* List of spelled out ordinals per AP style.
12+
* @private
13+
* @type {string[]}
14+
*/
15+
const AP_ORDINALS = [
16+
'first',
17+
'second',
18+
'third',
19+
'fourth',
20+
'fifth',
21+
'sixth',
22+
'seventh',
23+
'eighth',
24+
'ninth',
25+
];
26+
1027
/**
1128
* A list of funky English ordinals.
1229
* @private
13-
* @type {Array}
30+
* @type {number[]}
1431
*/
1532
const ENGLISH_ORDINAL_EXCEPTIONS = [11, 12, 13];
1633

1734
/**
18-
* Converts an integer into its ordinal form. Handles the special cases of 11,
19-
* 12 and 13, too. If a non-integer is submitted, it will be returned in its
20-
* original form.
35+
* Converts an integer into its ordinal form. If `spellOutOrdinals` is `true`,
36+
* 1 through 9 will be spelled out per AP style. Handles the special cases of
37+
* 11, 12 and 13, too. If a non-integer is submitted it will be returned in
38+
* its original form.
2139
*
2240
* @param {number|string} val
41+
* @param {boolean} [spellOutOrdinals]
2342
* @return {string}
2443
* @example
2544
*
@@ -33,8 +52,11 @@ const ENGLISH_ORDINAL_EXCEPTIONS = [11, 12, 13];
3352
*
3453
* journalize.ordinal(103);
3554
* // returns '103rd'
55+
*
56+
* journalize.ordinal(7, true);
57+
* // returns 'seventh'
3658
*/
37-
export default function ordinal(val) {
59+
export default function ordinal(val, spellOutOrdinals = false) {
3860
// if `val` is undefined or null, return an empty string
3961
if (isNil(val)) return '';
4062

@@ -43,9 +65,15 @@ export default function ordinal(val) {
4365
// if `convertedVal` is not an integer, return `val`
4466
if (!isInteger(convertedVal)) return val.toString();
4567

68+
// if `spellOutOrdinals` is true, return the spelled out versions of 1-9
69+
if (spellOutOrdinals && convertedVal < 10) {
70+
return AP_ORDINALS[convertedVal - 1];
71+
}
72+
4673
// if `convertedVal` is 11, 12 or 13, English gets weird
47-
if (ENGLISH_ORDINAL_EXCEPTIONS.indexOf(convertedVal % 100) > -1)
74+
if (ENGLISH_ORDINAL_EXCEPTIONS.indexOf(convertedVal % 100) > -1) {
4875
return convertedVal + SUFFIXES[0];
76+
}
4977

5078
return convertedVal + SUFFIXES[convertedVal % 10];
5179
}

src/pluralize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* alternative plural suffix can be provided as the second parameter, and if
77
* necessary, an alternative singular suffix can be provided as the third.
88
*
9-
* @param {number|string|Array} value
9+
* @param {number|string|array} value
1010
* @param {string} [pluralSuffix='s']
1111
* @param {string} [singularSuffix='']
1212
* @return {string}

src/yesno.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { isNil } from './utils';
55
* `null`/`undefined`, return a string according to the value. If `maybe` is not
66
* provided, a `null` or `undefined` value will return the `no` argument.
77
*
8-
* @param {boolean|Null|undefined} val
8+
* @param {boolean|null|undefined} val
99
* @param {string} [yes='yes']
1010
* @param {string} [no='no']
1111
* @param {string} [maybe='maybe']
12-
* @returns {string|boolean|Null|undefined}
12+
* @returns {string|boolean|null|undefined}
1313
* @example
1414
*
1515
* var journalize = require('journalize');

types/index.d.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ export function intcomma(val: number | string): string;
6565
export function intword(val: number | string): string;
6666

6767
/**
68-
* Converts an integer into its ordinal form. Handles the special cases of 11,
69-
* 12 and 13, too. If a non-integer is submitted, it will be returned in its
70-
* original form.
68+
* Converts an integer into its ordinal form. If `spellOutOrdinals` is `true`,
69+
* 1 through 9 will be spelled out per AP style. Handles the special cases of
70+
* 11, 12 and 13, too. If a non-integer is submitted it will be returned in
71+
* its original form.
7172
*
7273
* @param val The supplied value
74+
* @param spellOutOrdinals If true, 1 through 9 will be spelled out
7375
* @returns The converted value
7476
*/
75-
export function ordinal(val: number | string): string;
77+
export function ordinal(
78+
val: number | string,
79+
spellOutOrdinals?: boolean
80+
): string;
7681

7782
/**
7883
* Returns a plural suffix if the value is not 1. By default, `pluralize`

0 commit comments

Comments
 (0)