This file contains hidden or 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
const { pathsToModuleNameMapper } = require('ts-jest'); | |
const { compilerOptions } = require('./tsconfig.json'); | |
module.exports = { | |
preset: 'ts-jest', | |
testEnvironment: 'node', | |
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths), | |
modulePaths: ['<rootDir>'], | |
}; |
This file contains hidden or 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
npm i -D jest ts-jest prettier codecov cypress eslint eslint-config-prettier eslint-plugin-react @typescript-eslint/eslint-plugin @typescript-eslint/parser | |
npm i -D @types/jest |
This file contains hidden or 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
import React from 'react'; | |
interface ChildProps { | |
message: string; | |
} | |
const Child: React.FC<ChildProps> = ({ message }) => { | |
return <div>{message}</div>; | |
}; |
This file contains hidden or 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
// Step 1 | |
let data = { | |
name: "Chris Redfield", | |
age: 30, | |
job: "STARS soldier", | |
}; | |
// Step 2 (Serialisation Step) | |
let serialised = JSON.stringify(data); |
This file contains hidden or 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
// Step 1 | |
serialised := receiveSerialisedPayload(); | |
// Step 2 - We can deserialise into a struct with knowledge of the payload structure | |
type Person struct { | |
Name string `json:"name"` | |
Age int `json:"age"` | |
Job string `json:"job"` | |
} |
This file contains hidden or 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
// We have a string -> "{"name":"Chris Redfield","age":30,"job":"STARS soldier"}" | |
// The string represented as an array of bytes | |
// with decimal values where each byte ranges from 0 - 255 | |
[ | |
123, 34, 110, 97, 109, 101, 34, 58, 34, 67, | |
104, 114, 105, 115, 32, 82, 101, 100, 102, 105, | |
101, 108, 100, 34, 44, 34, 97, 103, 101, 34, | |
58, 51, 48, 44, 34, 106, 111, 98, 34, 58, | |
34, 83, 84, 65, 82, 83, 32, 115, 111, 108, |
This file contains hidden or 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
[ | |
'0x7b', '0x22', '0x6e', '0x61', '0x6d', | |
'0x65', '0x22', '0x3a', '0x22', '0x43', | |
'0x68', '0x72', '0x69', '0x73', '0x20', | |
'0x52', '0x65', '0x64', '0x66', '0x69', | |
'0x65', '0x6c', '0x64', '0x22', '0x2c', | |
'0x22', '0x61', '0x67', '0x65', '0x22', | |
'0x3a', '0x33', '0x30', '0x2c', '0x22', | |
'0x6a', '0x6f', '0x62', '0x22', '0x3a', | |
'0x22', '0x53', '0x54', '0x41', '0x52', |
This file contains hidden or 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
type Input = string | number | bigint | Uint8Array | Array<Input> | null | undefined | any; | |
function encode(input: Input): Uint8Array { | |
/* (1) Non-value input */ | |
if (input === '' || input === false || input === null) { | |
const value = parseInt('0x80', 16); | |
return Uint8Array.from([value]); | |
} | |
/* (2) Empty list input */ |
This file contains hidden or 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
/* If string supplied is prefixed with '0x' remove it and return the new string */ | |
function stripHexPrefix(input: string): string { | |
if (input.startsWith('0x')) { | |
input = input.slice(2); | |
} | |
return input; | |
} | |
/* Convert a hexadecimal string to an array of hexadecimal byte values (in preparation of inserting into a byte array) */ |
This file contains hidden or 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
{ | |
"difficulty":"0x1b315bd824e5e8", | |
"extraData":"0x65746865726d696e652d75732d7765737431", | |
"gasLimit":"0xe4e1b2", | |
"gasUsed":"0xe4dd4b", | |
"hash":"0x14687ccc4adfd2b0f0d530fc8f8c64dd29ac301ddea26e99087e11d0eae4f575", | |
"logsBloom":"0x2361a9b76107883d7089e585a3a1422374b21375b8168423507d70b2bccab1a10c5771c82882574255d25bb3c04747e9971ca844ed667b2407dbfb207a24ac5940985ec6f00a0b2c19baaaff217033b63ba7fc2467e64f816ace1764d9e90dd97f5098d2d383ae4951c21952e837eac70290d769b61b275e0a1f75d030382a06e890ef782655601487fc124d274a7626195724f7275409589d2f00e50a5b2914c3db2b5bb1de73284217e0d2f23fa4999a52fa4611e0a005292abd3e5b5d09ff13d12537398412f03416d82181fbb1939965568e078f2f1e65481b8eed3aea90f8f37e99c12fa02500ac1721c2409770d5b52440ab43c050277a2b93357970a7", | |
"miner":"0xea674fdde714fd979de3edf0f56aa9716b898ec8", | |
"mixHash":"0x7ae3558891959354b482938e5a61b1d7e371636e5a718137e16753f595531f6a", | |
"nonce":"0xb81e11f2cb22375e", |