Skip to content

Commit

Permalink
feat: working
Browse files Browse the repository at this point in the history
  • Loading branch information
tonioriol committed Oct 27, 2024
1 parent 44ec37d commit b52a177
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 573 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ interface UserDTO {
const schema = [
{
to: 'fullName',
fn: ({ entity }) => `${entity.firstName} ${entity.lastName}`
fn: ({ source }) => `${source.firstName} ${source.lastName}`
},
{
to: 'yearOfBirth',
fn: ({ entity }) => new Date().getFullYear() - entity.age
fn: ({ source }) => new Date().getFullYear() - source.age
}
];

Expand Down Expand Up @@ -92,7 +92,7 @@ interface PricedProduct {
const schema = [
{
to: 'finalPrice',
fn: ({ entity, extra }) => entity.price * (1 + extra.taxRate)
fn: ({ source, extra }) => source.price * (1 + extra.taxRate)
}
];

Expand All @@ -107,14 +107,14 @@ const pricedProduct = mutate<Product, PricedProduct>(

## API Reference

### `mutate<From, To>(schema, entity, extra?)`
### `mutate<Source, Target>(schema, source, extra?)`

Transforms a source entity into a target type based on the provided schema.
Transforms a source source into a target type based on the provided schema.

#### Parameters

- `schema`: Array of transformation rules defining how properties should be mapped or transformed
- `entity`: Source entity to transform
- `source`: Source source to transform
- `extra`: (Optional) Additional data to pass to transformation functions

#### Schema Options
Expand All @@ -131,7 +131,7 @@ Transforms a source entity into a target type based on the provided schema.
```typescript
{
to: keyof Target;
fn: (args: { entity: Source; extra?: Extra }) => unknown;
fn: (args: { source: Source; extra?: Extra }) => unknown;
}
```

Expand All @@ -140,7 +140,7 @@ Transforms a source entity into a target type based on the provided schema.
{
to: keyof Target;
from: keyof Source;
fn: (args: { entity: Source; from?: keyof Source; extra?: Extra }) => unknown;
fn: (args: { source: Source; from?: keyof Source; extra?: Extra }) => unknown;
}
```

Expand Down
83 changes: 0 additions & 83 deletions dist/index.d.ts

This file was deleted.

108 changes: 0 additions & 108 deletions dist/index.js

This file was deleted.

103 changes: 0 additions & 103 deletions dist/types.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions dist/types.js

This file was deleted.

Loading

0 comments on commit b52a177

Please sign in to comment.