Skip to content

Instantly share code, notes, and snippets.

@Grohden
Last active December 19, 2024 12:39
Show Gist options
  • Save Grohden/804db6900ec6409e943eae71591be22b to your computer and use it in GitHub Desktop.
Save Grohden/804db6900ec6409e943eae71591be22b to your computer and use it in GitHub Desktop.
Is react native hermes ready to be used, in any normal env that uses these libs?
// Once you think you're ready for hermes, you can include this file in the app
// and if it doesn't throw an error, you're good to go.
// https://github.com/facebook/hermes/issues/865
export const areWeReadyForHermesDatefns = () => {
const anyFailed = [
// This one just throws ¯\_(ツ)_/¯
testEq(
"new Date('July 30, 2022').toISOString()",
new Date('July 30, 2022').toISOString(),
'2022-07-30T03:00:00.000Z',
),
].some((result) => result);
if (anyFailed) {
throw new Error('Hermes is not ready to be used!');
}
console.log('Congrats! Hermes maybe ready to be used!');
};
const testEq = (expr: string, actual: unknown, expected: unknown) => {
if (actual !== expected) {
console.error(
`[FAILED] expected '${expr}' to be: ${expected} but got: ${actual}`,
);
return true;
}
return false;
};
import dayjs from 'dayjs';
// Once you think you're ready for hermes, you can include this file in the app
// and if it doesn't throw an error, you're good to go.
// https://github.com/iamkun/dayjs/issues/1377
// https://github.com/facebook/hermes/issues/865
export const areWeReadyForHermesDayjs = () => {
const anyFailed = [
testEq(
"dayjs('01/01/2024').isValid()",
dayjs('01/01/2024').isValid(),
true,
),
// This one just throws ¯\_(ツ)_/¯
testEq(
"dayjs('01/01/2024').toISOString()",
dayjs('05/05/2024').toISOString(),
'any',
),
].some((result) => result);
if (anyFailed) {
throw new Error('Hermes is not ready to be used!');
}
console.log('Congrats! Hermes maybe ready to be used!');
};
const testEq = (expr: string, actual: unknown, expected: unknown) => {
if (actual !== expected) {
console.error(
`[FAILED] expected '${expr}' to be: ${expected} but got: ${actual}`,
);
return true;
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment