-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from samchon/v2.0
- Loading branch information
Showing
13 changed files
with
445 additions
and
387 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import ts from "typescript"; | ||
|
||
export namespace ExpressionFactory | ||
{ | ||
export function generate(input: any) | ||
{ | ||
if (input instanceof Array) | ||
return generate_array(input); | ||
else if (typeof input === "object") | ||
return generate_object(input); | ||
else if (typeof input === "boolean") | ||
return generate_boolean(input); | ||
else if (typeof input === "string") | ||
return generate_string(input); | ||
else | ||
throw new Error("Unknown type."); | ||
} | ||
|
||
function generate_object(obj: object): ts.ObjectLiteralExpression | ||
{ | ||
const properties = Object | ||
.entries(obj) | ||
.map(([key, value]) => ts.factory.createPropertyAssignment | ||
( | ||
key, | ||
generate(value) | ||
)); | ||
return ts.factory.createObjectLiteralExpression(properties, true); | ||
} | ||
|
||
function generate_array(array: any[]): ts.ArrayLiteralExpression | ||
{ | ||
return ts.factory.createArrayLiteralExpression | ||
( | ||
array.map(generate), | ||
true | ||
); | ||
} | ||
|
||
function generate_boolean(value: boolean): ts.Identifier | ||
{ | ||
return ts.factory.createIdentifier(value.toString()); | ||
} | ||
|
||
function generate_string(value: string): ts.StringLiteral | ||
{ | ||
return ts.factory.createStringLiteral(value); | ||
} | ||
} |
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.
Oops, something went wrong.