-
Notifications
You must be signed in to change notification settings - Fork 42
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
3 changed files
with
24 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import export_ from './export' | ||
import import_ from './import' | ||
|
||
/** | ||
* Convert a thing from one format to another. | ||
* | ||
* @param thing The thing to convert as a string | ||
* @param from The current format of the thing as a MIME type e.g. `text/markdown` | ||
* @param to The desired format for the thing as a MIME type e.g. `text/html` | ||
*/ | ||
export default function convert (thing: string, from: string= 'application/ld+json', to: string= 'application/ld+json'): string { | ||
return export_(import_(thing, from), to) | ||
} |
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,8 @@ | ||
import convert from '../src/convert' | ||
|
||
test('convert:Thing', () => { | ||
const jsonld = '{"@context":"https://stencila.github.io/schema/context.jsonld","type":"Thing","name":"Thing1"}' | ||
expect(convert(jsonld, 'application/ld+json', 'application/ld+json')).toEqual(jsonld) | ||
expect(() => convert('blah', 'foo/bar')).toThrow(/^Unhandled import format: foo\/bar/) | ||
expect(() => convert('{"type":"Person"}', undefined, 'foo/bar')).toThrow(/^Unhandled export format: foo\/bar/) | ||
}) |