-
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.
- Loading branch information
Showing
6 changed files
with
56 additions
and
55 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "mutant", | ||
"name": "transmutant", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
|
@@ -16,6 +16,7 @@ | |
"keywords": [ | ||
"transform", | ||
"mutation", | ||
"transmutation", | ||
"typescript", | ||
"schema", | ||
"mapping", | ||
|
@@ -24,7 +25,7 @@ | |
], | ||
"author": "Toni Oriol <[email protected]> (http://tonioriol.com/)", | ||
"license": "MIT", | ||
"description": "Transform your data with the power of mutation 🧬", | ||
"description": "Powerful type transmutations for TypeScript 🧬", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"jest": "^29.7.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { mutate, Schema } from '../' | ||
import { transmute, Schema } from '../' | ||
|
||
interface SourceUser { | ||
firstName: string | ||
|
@@ -20,7 +20,7 @@ interface TargetUser { | |
isAdult: boolean | ||
} | ||
|
||
describe('mutate', () => { | ||
describe('transmute', () => { | ||
const sourceUser: SourceUser = { | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
|
@@ -38,35 +38,35 @@ describe('mutate', () => { | |
{ from: 'email', to: 'contactEmail' } | ||
] | ||
|
||
const result = mutate(schema, sourceUser) | ||
const result = transmute(schema, sourceUser) | ||
expect(result).toEqual({ contactEmail: '[email protected]' }) | ||
}) | ||
|
||
it('should handle custom transformation functions', () => { | ||
it('should handle custom transmutation functions', () => { | ||
const schema: Schema<SourceUser, Pick<TargetUser, 'fullName'>>[] = [ | ||
{ | ||
to: 'fullName', | ||
fn: ({ source }) => `${source.firstName} ${source.lastName}` | ||
} | ||
] | ||
|
||
const result = mutate(schema, sourceUser) | ||
const result = transmute(schema, sourceUser) | ||
expect(result).toEqual({ fullName: 'John Doe' }) | ||
}) | ||
|
||
it('should handle transformation with both "from" and "fn"', () => { | ||
it('should handle transmutation with both "from" and "fn"', () => { | ||
const schema: Schema<SourceUser, Pick<TargetUser, 'userAge'>>[] = [ | ||
{ | ||
to: 'userAge', | ||
fn: ({ source }) => source['age'] + 1 | ||
} | ||
] | ||
|
||
const result = mutate(schema, sourceUser) | ||
const result = transmute(schema, sourceUser) | ||
expect(result).toEqual({ userAge: 26 }) | ||
}) | ||
|
||
it('should handle extra data in transformations', () => { | ||
it('should handle extra data in transmutations', () => { | ||
const schema: Schema<SourceUser, Pick<TargetUser, 'location'>>[] = [ | ||
{ | ||
to: 'location', | ||
|
@@ -75,11 +75,11 @@ describe('mutate', () => { | |
} | ||
] | ||
|
||
const result = mutate(schema, sourceUser, { separator: ' | ' }) | ||
const result = transmute(schema, sourceUser, { separator: ' | ' }) | ||
expect(result).toEqual({ location: 'New York, USA | ' }) | ||
}) | ||
|
||
it('should handle multiple transformations', () => { | ||
it('should handle multiple transmutations', () => { | ||
const schema: Schema<SourceUser, TargetUser>[] = [ | ||
{ | ||
to: 'fullName', | ||
|
@@ -104,7 +104,7 @@ describe('mutate', () => { | |
} | ||
] | ||
|
||
const result = mutate(schema, sourceUser) | ||
const result = transmute(schema, sourceUser) | ||
expect(result).toEqual({ | ||
fullName: 'John Doe', | ||
userAge: 25, | ||
|
@@ -114,21 +114,21 @@ describe('mutate', () => { | |
}) | ||
}) | ||
|
||
it('should set null for undefined transformations', () => { | ||
it('should set null for undefined transmutations', () => { | ||
const schema: Schema<SourceUser, { optionalField: string }>[] = [ | ||
{ | ||
to: 'optionalField', | ||
from: 'nonexistentField' as keyof SourceUser | ||
} | ||
] | ||
|
||
const result = mutate(schema, sourceUser) | ||
const result = transmute(schema, sourceUser) | ||
expect(result).toEqual({ optionalField: null }) | ||
}) | ||
|
||
it('should handle empty schema', () => { | ||
const schema: Schema<SourceUser, {}>[] = [] | ||
const result = mutate(schema, sourceUser) | ||
const result = transmute(schema, sourceUser) | ||
expect(result).toEqual({}) | ||
}) | ||
|
||
|
@@ -142,7 +142,7 @@ describe('mutate', () => { | |
{ from: 'email', to: 'contactEmail' } | ||
] | ||
|
||
const result = mutate(schema, sourceWithNull) | ||
const result = transmute(schema, sourceWithNull) | ||
expect(result).toEqual({ contactEmail: null }) | ||
}) | ||
}) |
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