Skip to content

Commit

Permalink
Dev (#1)
Browse files Browse the repository at this point in the history
* works with deno 1.8.1

* up readme

* Merge branch 'dev' of github.com:Tnifey/class-transformer into dev

* Merge branch 'dev' of github.com:Tnifey/class-transformer into dev

* up readme

* up readme

* up readme

Co-authored-by: Hubert Lesiak <hubert.lesiak@gmail.com>
  • Loading branch information
Tnifey and hubert-lesiak authored Mar 16, 2021
1 parent 2a1df5c commit 2160ee0
Show file tree
Hide file tree
Showing 10 changed files with 999 additions and 960 deletions.
1,762 changes: 915 additions & 847 deletions README.md

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions scripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "https://deno.land/x/denon@2.4.7/schema.json",
"scripts": {
"start": {
"cmd": "deno run app.ts",
"desc": "run my app.ts file"
},
"dev": {
"cmd": "deno run example.ts",
"desc": "run my app.ts file",
"watch": true,
"allow": ["env"]
}
},
"tsconfig": "tsconfig.json"
}
62 changes: 31 additions & 31 deletions src/ClassTransformOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/
export interface TargetMap {
/**
* Target which Types are being specified.
*/
* Target which Types are being specified.
*/
target: Function;

/**
* List of properties and their Types.
*/
* List of properties and their Types.
*/
properties: { [key: string]: Function };
}

Expand All @@ -19,56 +19,56 @@ export interface TargetMap {
*/
export interface ClassTransformOptions {
/**
* Exclusion strategy. By default exposeAll is used, which means that it will expose all properties are transformed
* by default.
*/
* Exclusion strategy. By default exposeAll is used, which means that it will expose all properties are transformed
* by default.
*/
strategy?: "excludeAll" | "exposeAll";

/**
* Indicates if extraneous properties should be excluded from the value when converting a plain value to a class.
*/
* Indicates if extraneous properties should be excluded from the value when converting a plain value to a class.
*/
excludeExtraneousValues?: boolean;

/**
* Only properties with given groups gonna be transformed.
*/
* Only properties with given groups gonna be transformed.
*/
groups?: string[];

/**
* Only properties with "since" > version < "until" gonna be transformed.
*/
* Only properties with "since" > version < "until" gonna be transformed.
*/
version?: number;

/**
* Excludes properties with the given prefixes. For example, if you mark your private properties with "_" and "__"
* you can set this option's value to ["_", "__"] and all private properties will be skipped.
* This works only for "exposeAll" strategy.
*/
* Excludes properties with the given prefixes. For example, if you mark your private properties with "_" and "__"
* you can set this option's value to ["_", "__"] and all private properties will be skipped.
* This works only for "exposeAll" strategy.
*/
excludePrefixes?: string[];

/**
* If set to true then class transformer will ignore all @Expose and @Exclude decorators and what inside them.
* This option is useful if you want to kinda clone your object but do not apply decorators affects.
*/
* If set to true then class transformer will ignore all @Expose and @Exclude decorators and what inside them.
* This option is useful if you want to kinda clone your object but do not apply decorators affects.
*/
ignoreDecorators?: boolean;

/**
* Target maps allows to set a Types of the transforming object without using @Type decorator.
* This is useful when you are transforming external classes, or if you already have type metadata for
* objects and you don't want to set it up again.
*/
* Target maps allows to set a Types of the transforming object without using @Type decorator.
* This is useful when you are transforming external classes, or if you already have type metadata for
* objects and you don't want to set it up again.
*/
targetMaps?: TargetMap[];

/**
* If set to true then class transformer will perform a circular check. (circular check is turned off by default)
* This option is useful when you know for sure that your types might have a circular dependency.
*/
* If set to true then class transformer will perform a circular check. (circular check is turned off by default)
* This option is useful when you know for sure that your types might have a circular dependency.
*/
enableCircularCheck?: boolean;

/**
* If set to true then class transformer will try to convert properties implicitly to their target type based on their typing information.
*
* DEFAULT: `false`
*/
* If set to true then class transformer will try to convert properties implicitly to their target type based on their typing information.
*
* DEFAULT: `false`
*/
enableImplicitConversion?: boolean;
}
2 changes: 1 addition & 1 deletion src/ClassTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ClassTransformOptions } from "./ClassTransformOptions.ts";
import {
TransformOperationExecutor,
TransformationType,
TransformOperationExecutor,
} from "./TransformOperationExecutor.ts";

export type ClassType<T> = {
Expand Down
6 changes: 3 additions & 3 deletions src/TransformOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Buffer } from "https://deno.land/std/node/buffer.ts";
import { ClassTransformOptions } from "./ClassTransformOptions.ts";
import { defaultMetadataStorage } from "./storage.ts";
import {
Discriminator,
JsonSubType,
TypeHelpOptions,
TypeOptions,
JsonSubType,
Discriminator,
} from "./metadata/ExposeExcludeOptions.ts";
import { TypeMetadata } from "./metadata/TypeMetadata.ts";

Expand Down Expand Up @@ -46,7 +46,7 @@ export class TransformOperationExecutor {
) {
if (Array.isArray(value) || value instanceof Set) {
const newValue = arrayType &&
this.transformationType === TransformationType.PLAIN_TO_CLASS
this.transformationType === TransformationType.PLAIN_TO_CLASS
? instantiateArrayType(arrayType)
: [];

Expand Down
6 changes: 3 additions & 3 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { defaultMetadataStorage } from "./storage.ts";
import { TypeMetadata } from "./metadata/TypeMetadata.ts";
import { ExposeMetadata } from "./metadata/ExposeMetadata.ts";
import {
ExposeOptions,
Discriminator,
ExcludeOptions,
TypeHelpOptions,
ExposeOptions,
TransformOptions,
Discriminator,
TypeHelpOptions,
TypeOptions,
} from "./metadata/ExposeExcludeOptions.ts";
import { ExcludeMetadata } from "./metadata/ExcludeMetadata.ts";
Expand Down
35 changes: 22 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
if (!("getMetadata" in Reflect)) {
const { bold, bgRed, white } = await import(
"https://deno.land/std/fmt/colors.ts"
);

const fmt = (text: string) => bold(bgRed(white(text.toUpperCase())));

console.log(
"\n",
fmt(`!!! import reflect-metadata into your main file !!!`),
`\n--> import "https://raw.githubusercontent.com/rbuckton/reflect-metadata/v0.1.12/Reflect.js"`,
"\n",
`!!! import reflect-metadata into your main file !!!`,
`\n--> import "https://esm.sh/reflect-metadata";`,
`\n it checks for 'process.env.REFLECT_METADATA_USE_MAP_POLYFILL' so need --allow-env flag`,
);
}

import { ClassTransformer, ClassType } from "./ClassTransformer.ts";
import { ClassTransformOptions } from "./ClassTransformOptions.ts";

export { ClassTransformer } from "./ClassTransformer.ts";
export { ClassTransformOptions } from "./ClassTransformOptions.ts";
export * from "./metadata/ExposeExcludeOptions.ts";
export * from "./decorators.ts";
export type { ClassTransformOptions } from "./ClassTransformOptions.ts";
export type {
Discriminator,
ExcludeOptions,
ExposeOptions,
JsonSubType,
TransformOptions,
TypeHelpOptions,
TypeOptions,
} from "./metadata/ExposeExcludeOptions.ts";
export {
Exclude,
Expose,
Transform,
TransformClassToClass,
TransformClassToPlain,
TransformPlainToClass,
Type,
} from "./decorators.ts";

const classTransformer = new ClassTransformer();

Expand Down
2 changes: 1 addition & 1 deletion src/metadata/TypeMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
TypeHelpOptions,
Discriminator,
TypeHelpOptions,
TypeOptions,
} from "./ExposeExcludeOptions.ts";

Expand Down
14 changes: 7 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true
}
}
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false
}
}
54 changes: 0 additions & 54 deletions tslint.json

This file was deleted.

0 comments on commit 2160ee0

Please sign in to comment.