Fixed typings. Now string values correctly assignable to enum-like options

This commit is contained in:
sanex3339
2020-01-03 19:41:21 +03:00
parent b7edcdc375
commit 2f27d75318
15 changed files with 72 additions and 35 deletions
+11 -5
View File
@@ -1,5 +1,11 @@
export enum ObfuscationTarget {
Browser = 'browser',
BrowserNoEval = 'browser-no-eval',
Node = 'node'
}
import { MakeEnum } from '@gradecam/tsenum';
export const ObfuscationTarget: Readonly<{
BrowserNoEval: string;
Node: string;
Browser: string;
}> = MakeEnum({
Browser: 'browser',
BrowserNoEval: 'browser-no-eval',
Node: 'node'
});
+9 -4
View File
@@ -1,4 +1,9 @@
export enum StringArrayEncoding {
Base64 = 'base64',
Rc4 = 'rc4'
}
import { MakeEnum } from '@gradecam/tsenum';
export const StringArrayEncoding: Readonly<{
Rc4: string;
Base64: string;
}> = MakeEnum({
Base64: 'base64',
Rc4: 'rc4'
});
@@ -1,5 +1,11 @@
export enum IdentifierNamesGenerator {
DictionaryIdentifierNamesGenerator = 'dictionary',
HexadecimalIdentifierNamesGenerator = 'hexadecimal',
MangledIdentifierNamesGenerator = 'mangled'
}
import { MakeEnum } from '@gradecam/tsenum';
export const IdentifierNamesGenerator: Readonly<{
MangledIdentifierNamesGenerator: string;
DictionaryIdentifierNamesGenerator: string;
HexadecimalIdentifierNamesGenerator: string;
}> = MakeEnum({
DictionaryIdentifierNamesGenerator: 'dictionary',
HexadecimalIdentifierNamesGenerator: 'hexadecimal',
MangledIdentifierNamesGenerator: 'mangled'
});
+9 -4
View File
@@ -1,4 +1,9 @@
export enum SourceMapMode {
Inline = 'inline',
Separate = 'separate'
}
import { MakeEnum } from '@gradecam/tsenum';
export const SourceMapMode: Readonly<{
Separate: string;
Inline: string;
}> = MakeEnum({
Inline: 'inline',
Separate: 'separate'
});
+5 -3
View File
@@ -1,3 +1,5 @@
import { TypeFromEnum } from '@gradecam/tsenum';
import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
import { IdentifierNamesGenerator } from '../../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
@@ -14,7 +16,7 @@ export interface IOptions {
readonly debugProtectionInterval: boolean;
readonly disableConsoleOutput: boolean;
readonly domainLock: string[];
readonly identifierNamesGenerator: IdentifierNamesGenerator;
readonly identifierNamesGenerator: TypeFromEnum<typeof IdentifierNamesGenerator>;
readonly identifiersDictionary: string[];
readonly identifiersPrefix: string;
readonly inputFileName: string;
@@ -28,13 +30,13 @@ export interface IOptions {
readonly sourceMap: boolean;
readonly sourceMapBaseUrl: string;
readonly sourceMapFileName: string;
readonly sourceMapMode: SourceMapMode;
readonly sourceMapMode: TypeFromEnum<typeof SourceMapMode>;
readonly splitStrings: boolean;
readonly splitStringsChunkLength: number;
readonly stringArray: boolean;
readonly stringArrayEncoding: TStringArrayEncoding;
readonly stringArrayThreshold: number;
readonly target: ObfuscationTarget;
readonly target: TypeFromEnum<typeof ObfuscationTarget>;
readonly transformObjectKeys: boolean;
readonly unicodeEscapeSequence: boolean;
}
+5 -3
View File
@@ -1,3 +1,5 @@
import { TypeFromEnum } from '@gradecam/tsenum';
import { inject, injectable } from 'inversify';
import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
@@ -112,7 +114,7 @@ export class Options implements IOptions {
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
])
public readonly identifierNamesGenerator!: IdentifierNamesGenerator;
public readonly identifierNamesGenerator!: TypeFromEnum<typeof IdentifierNamesGenerator>;
/**
* @type {string}
@@ -214,7 +216,7 @@ export class Options implements IOptions {
* @type {SourceMapMode}
*/
@IsIn([SourceMapMode.Inline, SourceMapMode.Separate])
public readonly sourceMapMode!: SourceMapMode;
public readonly sourceMapMode!: TypeFromEnum<typeof SourceMapMode>;
/**
* @type {boolean}
@@ -254,7 +256,7 @@ export class Options implements IOptions {
* @type {ObfuscationTarget}
*/
@IsIn([ObfuscationTarget.Browser, ObfuscationTarget.BrowserNoEval, ObfuscationTarget.Node])
public readonly target!: ObfuscationTarget;
public readonly target!: TypeFromEnum<typeof ObfuscationTarget>;
/**
* @type {boolean}
+3 -1
View File
@@ -1,3 +1,5 @@
import { TypeFromEnum } from '@gradecam/tsenum';
import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
export type TStringArrayEncoding = boolean | StringArrayEncoding;
export type TStringArrayEncoding = boolean | TypeFromEnum<typeof StringArrayEncoding>;