-
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.
* + Add code formatter. * + Revert editorconfig. * + Update README.md
- Loading branch information
1 parent
fdcbe12
commit 0ad3581
Showing
22 changed files
with
415 additions
and
267 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
{ | ||
"env": { | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"standard", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"indent": ["error", 2, { "SwitchCase": 1, "ignoredNodes": ["PropertyDefinition"] }], | ||
"@typescript-eslint/no-inferrable-types": 0 | ||
} | ||
} |
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,22 @@ | ||
/* @ts-check */ | ||
|
||
// This resolver is for using ESLint within Jest. | ||
|
||
// temporary workaround - https://github.com/facebook/jest/issues/9771#issuecomment-871585234 | ||
const resolver = require('enhanced-resolve').create.sync({ | ||
conditionNames: ['require', 'node', 'default'], | ||
extensions: ['.js', '.json', '.node', '.ts', '.tsx'], | ||
}); | ||
|
||
/** | ||
* @param request {unknown} | ||
* @param options {{ defaultResolver(...args: unknown[]): unknown, basedir: unknown }} | ||
* @returns {unknown} | ||
*/ | ||
module.exports = function (request, options) { | ||
// list global module that must be resolved by defaultResolver here | ||
if (['fs', 'http', 'path'].includes(request)) { | ||
return options.defaultResolver(request, options); | ||
} | ||
return resolver(options.basedir, request); | ||
}; |
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,6 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
resolver: '<rootDir>/.jest/resolver.js', | ||
preset: 'ts-jest', | ||
testEnvironment: 'node' | ||
} |
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 @@ | ||
const codeFormat = (code: string) => { | ||
return code.replace(/ {4}/g, ' ') | ||
.replace(/\r\n/g, '\n') | ||
.replace(/;/g, '\n') | ||
.replace(/"/g, '\'') | ||
.replace(/\n\n}/g, '\n}\n') | ||
.replace(/}\n\n/g, '}\n') | ||
.replace(/\n@Serializable/g, '\n\n@Serializable') | ||
} | ||
|
||
export { | ||
codeFormat | ||
} |
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,84 @@ | ||
import ts from 'typescript' | ||
import { isBoolean, isNumber, isString } from './utils' | ||
|
||
const getSyntaxKind = (target: unknown) => { | ||
if (isNumber(target)) { | ||
return ts.SyntaxKind.NumberKeyword | ||
} | ||
|
||
if (isBoolean(target)) { | ||
return ts.SyntaxKind.BooleanKeyword | ||
} | ||
|
||
if (isString(target)) { | ||
return ts.SyntaxKind.StringKeyword | ||
} | ||
|
||
return ts.SyntaxKind.UnknownKeyword | ||
} | ||
|
||
const getInitializer = (target: unknown): ts.Expression => { | ||
if (isNumber(target)) { | ||
return ts.factory.createNumericLiteral(0) | ||
} | ||
|
||
if (isBoolean(target)) { | ||
return ts.factory.createFalse() | ||
} | ||
|
||
if (isString(target)) { | ||
return ts.factory.createStringLiteral('') | ||
} | ||
|
||
return ts.factory.createNull() | ||
} | ||
|
||
const createSerializableDecorator = () => { | ||
return ts.factory.createDecorator( | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier('Serializable'), undefined, [] | ||
) | ||
) | ||
} | ||
|
||
const createJsonPropertyDecorator = (propName: string) => { | ||
return ts.factory.createDecorator( | ||
ts.factory.createCallExpression( | ||
ts.factory.createIdentifier('JsonProperty'), | ||
undefined, | ||
[ | ||
ts.factory.createStringLiteral(propName) | ||
] | ||
) | ||
) | ||
} | ||
|
||
const printTsCode = (node: ts.Node): string => { | ||
const resultFile = ts.createSourceFile( | ||
'test.ts', | ||
'', | ||
ts.ScriptTarget.Latest, | ||
false, | ||
ts.ScriptKind.TS | ||
) | ||
|
||
const printer = ts.createPrinter({ | ||
newLine: ts.NewLineKind.LineFeed | ||
}) | ||
|
||
const result = printer.printNode( | ||
ts.EmitHint.Unspecified, | ||
node, | ||
resultFile | ||
) | ||
|
||
return result | ||
} | ||
|
||
export { | ||
getSyntaxKind, | ||
getInitializer, | ||
createSerializableDecorator, | ||
createJsonPropertyDecorator, | ||
printTsCode | ||
} |
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.