This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Primitive types): Add schemas for primitive types
This allows these types to be included in the list of types and have URIs generated for them. See this for why this is needed: https://github.com/stencila/encoda/blob/356b8e08f71880f12236bac7b0bcb2c272f4f60b/src/codecs/html/microdata.ts#L148
- Loading branch information
Showing
14 changed files
with
100 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
title: Array | ||
'@id': stencila:Array | ||
description: A value comprised of several other values. | ||
type: array |
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,4 @@ | ||
title: Boolean | ||
'@id': schema:Boolean | ||
description: A value that is either true or false | ||
type: boolean |
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,4 @@ | ||
title: 'Null' | ||
'@id': stencila:Null | ||
description: The null value | ||
type: '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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
title: Number | ||
'@id': schema:Number | ||
description: A value that is a number | ||
type: number |
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,4 @@ | ||
title: Object | ||
'@id': stencila:Object | ||
description: A value comprised of keyed values. | ||
type: object |
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,4 @@ | ||
title: Text | ||
'@id': schema:Text | ||
description: A value comprised of a string of characters | ||
type: string |
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
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { nodeType } from './node-type' | ||
|
||
test('nodeType', () => { | ||
expect(nodeType(null)).toBe('null') | ||
expect(nodeType(true)).toBe('boolean') | ||
expect(nodeType(false)).toBe('boolean') | ||
expect(nodeType(42)).toBe('number') | ||
expect(nodeType(3.14)).toBe('number') | ||
expect(nodeType('str')).toBe('string') | ||
expect(nodeType([])).toBe('array') | ||
expect(nodeType({})).toBe('object') | ||
expect(nodeType(null)).toBe('Null') | ||
expect(nodeType(true)).toBe('Boolean') | ||
expect(nodeType(false)).toBe('Boolean') | ||
expect(nodeType(42)).toBe('Number') | ||
expect(nodeType(3.14)).toBe('Number') | ||
expect(nodeType('str')).toBe('Text') | ||
expect(nodeType([])).toBe('Array') | ||
expect(nodeType({})).toBe('Object') | ||
expect(nodeType({ type: 'Person' })).toBe('Person') | ||
}) |
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,16 +1,17 @@ | ||
import { Node } from '../types' | ||
import { Types, Node } from '../types' | ||
import { isEntity } from './guards' | ||
|
||
/** | ||
* Get the type of a node | ||
* | ||
* @param {Node} node The schema node to get the type for | ||
*/ | ||
export const nodeType = (node: Node): string => { | ||
if (node === null) return 'null' | ||
if (typeof node === 'boolean') return 'boolean' | ||
if (typeof node === 'number') return 'number' | ||
if (typeof node === 'string') return 'string' | ||
if (Array.isArray(node)) return 'array' | ||
export const nodeType = (node: Node): keyof Types => { | ||
if (node === null) return 'Null' | ||
if (typeof node === 'boolean') return 'Boolean' | ||
if (typeof node === 'number') return 'Number' | ||
if (typeof node === 'string') return 'Text' | ||
if (Array.isArray(node)) return 'Array' | ||
if (isEntity(node)) return node.type | ||
return typeof node | ||
return 'Object' | ||
} |