-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
9ba554d
commit fd552ca
Showing
4 changed files
with
83 additions
and
0 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
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,45 @@ | ||
import test from 'node:test' | ||
import assert from 'node:assert/strict' | ||
|
||
import transformer from './type.js' | ||
|
||
// Setup | ||
|
||
const options = {} | ||
|
||
const state = { | ||
rev: false, | ||
onlyMappedValues: false, | ||
context: [], | ||
value: {}, | ||
} | ||
|
||
const stateRev = { ...state, rev: true } | ||
|
||
// Tests -- forward | ||
|
||
test('should return the type a value', () => { | ||
assert.equal(transformer({})(options)('I am a string', state), 'string') | ||
assert.equal(transformer({})(options)(32, state), 'number') | ||
assert.equal(transformer({})(options)(32.4, state), 'number') | ||
assert.equal(transformer({})(options)(true, state), 'boolean') | ||
assert.equal(transformer({})(options)(false, state), 'boolean') | ||
assert.equal(transformer({})(options)(new Date(), state), 'date') | ||
assert.equal(transformer({})(options)({}, state), 'object') | ||
assert.equal(transformer({})(options)(null, state), 'null') | ||
assert.equal(transformer({})(options)(undefined, state), 'undefined') | ||
}) | ||
|
||
// Tests -- reverse | ||
|
||
test('should return the type a value in reverse', () => { | ||
assert.equal(transformer({})(options)('I am a string', stateRev), 'string') | ||
assert.equal(transformer({})(options)(32, stateRev), 'number') | ||
assert.equal(transformer({})(options)(32.4, stateRev), 'number') | ||
assert.equal(transformer({})(options)(true, stateRev), 'boolean') | ||
assert.equal(transformer({})(options)(false, stateRev), 'boolean') | ||
assert.equal(transformer({})(options)(new Date(), stateRev), 'date') | ||
assert.equal(transformer({})(options)({}, stateRev), 'object') | ||
assert.equal(transformer({})(options)(null, stateRev), 'null') | ||
assert.equal(transformer({})(options)(undefined, stateRev), 'undefined') | ||
}) |
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,15 @@ | ||
import { isDate } from './utils/is.js' | ||
import type { Transformer } from 'integreat' | ||
|
||
const transformer: Transformer = () => () => | ||
function type(data) { | ||
if (isDate(data)) { | ||
return 'date' | ||
} else if (data === null) { | ||
return 'null' | ||
} else { | ||
return typeof data | ||
} | ||
} | ||
|
||
export default transformer |