-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* break randomInt * v1 more * files * readme * changelog * fix random Int * miss * randomDate * ch
- Loading branch information
Showing
23 changed files
with
164 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { formatLatin } from "./formatLatin"; | ||
|
||
const accentString = | ||
"áéíóúüñ¿¡àâèêëîïôûàãàãçàèéìòóùäöüßáéíóúáéíóúąćęłńóśźżáčďéěíňóřšťúůýžćčđšžáéíóúüαβγδεζηθικλμνξοπρστυφχψωçğıİöşüابتثجحخدذرزسشصضطظعغ"; | ||
const latinString = "aeiou"; | ||
|
||
describe("formatLatin", () => { | ||
test("should return a-z", () => { | ||
expect(formatLatin(accentString)).toBe(latinString); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const formatLatin = (text: string): string => { | ||
let normalized = text.normalize("NFKD"); | ||
return normalized; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { max } from "./max"; | ||
import { min } from "./min"; | ||
import { normaliseNumber } from "./normaliseNumber"; | ||
|
||
/** | ||
* Normalises an array of numbers | ||
* @example normaliseArray([1, 2, 3]) => [0, 0.5, 1] | ||
*/ | ||
export const normaliseArray = (values: number[]) => { | ||
const minValue = min(values); | ||
const maxValue = max(values); | ||
|
||
return values.map((value) => normaliseNumber(value, minValue, maxValue)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* | ||
* @example normaliseNumber(50, 0, 100) => 0.5 | ||
*/ | ||
export const normaliseNumber = ( | ||
value: number, | ||
minValue: number, | ||
maxValue: number | ||
) => (value - minValue) / (maxValue - minValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { isPositiveInt } from "../validators"; | ||
|
||
export const percentageChange = ({ | ||
previous, | ||
current, | ||
}: { | ||
previous: number; | ||
current: number; | ||
}): number => { | ||
if (!isPositiveInt(previous) || !isPositiveInt(current)) return 0; | ||
/** | ||
* | ||
* @param previous Positive percentage i.e. 0.1 for 10% | ||
* @param current Positive percentage i.e. 0.2 for 20% | ||
* @returns | ||
*/ | ||
export const percentageChange = (previous: number, current: number): number => { | ||
if (previous < 0 || current < 0) return 0; | ||
if (current === 0 && previous === 0) return 0; | ||
if (current === 0 && previous !== 0) return -100; | ||
if (current !== 0 && previous === 0) return 100; | ||
const perChange = ((current - previous) * 100) / previous; | ||
return parseFloat(perChange.toFixed(2)); | ||
if (current === 0 && previous !== 0) return -1; | ||
if (current !== 0 && previous === 0) return 1; | ||
const perChange = (current - previous) / previous; | ||
return parseFloat(perChange.toFixed(4)); // 4 decimal places so when formatting to % two decimal places are shown | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { randomInt } from "./randomInt"; | ||
import { randomArrayItem } from "./randomArrayItem"; | ||
|
||
export const randomBool = () => !!randomInt(0, 1); | ||
export const randomBool = () => randomArrayItem([true, false]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { randomInt } from "./randomInt"; | ||
|
||
export const randomChar = () => { | ||
return String.fromCharCode(randomInt(97, 122)); | ||
return String.fromCharCode(randomInt({ min: 97, max: 122 })); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.