-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(serializer): split serializers (#12)
* feat(serializer): split serializers * test: fix serializer test file path
- Loading branch information
1 parent
6d8ba6f
commit bfb7637
Showing
10 changed files
with
242 additions
and
235 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 was deleted.
Oops, something went wrong.
File renamed without changes.
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,30 @@ | ||
import Handle from './Handle.js'; | ||
|
||
export type SerializableValue = | ||
| number | boolean | string | null | undefined | bigint | URL | Date | Error | RegExp | Handle | ||
| SerializableValue[] | { [K: string]: SerializableValue }; | ||
|
||
export interface SerializedValue { | ||
i: number; // ID | ||
n?: number | boolean | string | null; | ||
v?: 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0'; | ||
b?: string; // BigInt | ||
u?: string; // URL | ||
d?: string; // Date | ||
r?: { | ||
p: string; | ||
f: string; | ||
}, // RegExp | ||
h?: number; // Handle ID | ||
e?: { | ||
n: string; | ||
m: string; | ||
c?: SerializedValue | undefined; | ||
s?: string | undefined; | ||
}; // Error | ||
a?: SerializedValue[]; // Array | ||
o?: { | ||
k: string; | ||
v: SerializedValue; | ||
}[]; // Object | ||
} |
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,13 @@ | ||
import Handle from './Handle.js'; | ||
import serializeValue, { noFallback } from './serializeValue.js'; | ||
import parseSerializedValue from './parseSerializedValue.js'; | ||
import parseEvaluateExpression from './parseEvaluateExpression.js'; | ||
|
||
export * from './Serializable.js'; | ||
export { | ||
parseEvaluateExpression, | ||
parseSerializedValue, | ||
serializeValue, | ||
noFallback, | ||
Handle, | ||
}; |
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 @@ | ||
export default function parseEvaluateExpression(expression: string): unknown { | ||
const exp = expression.trim(); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-implied-eval | ||
return new Function(`return (${exp})`)(); | ||
} catch { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-implied-eval | ||
return new Function(`return (${exp.replace(/^(async )?/, '$1function ')})`)(); | ||
} catch { | ||
throw new Error('Passed function is not well-serializable!'); | ||
} | ||
} | ||
} |
Oops, something went wrong.