Comparing version 2.0.0 to 2.1.0
@@ -425,2 +425,3 @@ var __defProp = Object.defineProperty; | ||
floorTo: () => floorTo, | ||
getOrdinal: () => getOrdinal, | ||
lerp: () => lerp, | ||
@@ -526,2 +527,18 @@ lerpArray: () => lerpArray, | ||
var clamp = (value, min, max) => Math.max(Math.min(min, max), Math.min(value, Math.max(min, max))); | ||
var getOrdinal = (num = 0) => { | ||
const lastDigit = num % 10; | ||
if ([11, 12, 13].includes(num)) { | ||
return "th"; | ||
} | ||
if (lastDigit === 1) { | ||
return "st"; | ||
} | ||
if (lastDigit === 2) { | ||
return "nd"; | ||
} | ||
if (lastDigit === 3) { | ||
return "rd"; | ||
} | ||
return "th"; | ||
}; | ||
@@ -528,0 +545,0 @@ // src/tools/fn.ts |
{ | ||
"name": "swiss-ak", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"author": "Jack Cannon <jackc@annon.co.uk> (http://c.annon.co.uk/)", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -159,1 +159,43 @@ import { zip } from './ArrayTools'; | ||
export const clamp = (value: number, min: number, max: number) => Math.max(Math.min(min, max), Math.min(value, Math.max(min, max))); | ||
/**<!-- DOCS: ### --> | ||
* getOridinal | ||
* | ||
* - `MathsTools.getOridinal` | ||
* | ||
* Gets the ordinal suffix for a number. | ||
* | ||
* ```typescript | ||
* MathsTools.getOridinal(1); // 'st' | ||
* MathsTools.getOridinal(2); // 'nd' | ||
* MathsTools.getOridinal(3); // 'rd' | ||
* MathsTools.getOridinal(4); // 'th' | ||
* | ||
* MathsTools.getOridinal(11); // 'th' | ||
* MathsTools.getOridinal(12); // 'th' | ||
* MathsTools.getOridinal(13); // 'th' | ||
* MathsTools.getOridinal(14); // 'th' | ||
* | ||
* MathsTools.getOridinal(21); // 'st' | ||
* MathsTools.getOridinal(22); // 'nd' | ||
* MathsTools.getOridinal(23); // 'rd' | ||
* MathsTools.getOridinal(24); // 'th' | ||
* ``` | ||
*/ | ||
export const getOrdinal = (num: number = 0) => { | ||
const lastDigit = num % 10; | ||
if ([11, 12, 13].includes(num)) { | ||
return 'th'; | ||
} | ||
if (lastDigit === 1) { | ||
return 'st'; | ||
} | ||
if (lastDigit === 2) { | ||
return 'nd'; | ||
} | ||
if (lastDigit === 3) { | ||
return 'rd'; | ||
} | ||
return 'th'; | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
364089
9944
2340