Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support output as commonjs/es modules/typescript #4

Merged
merged 4 commits into from
Sep 8, 2020

Conversation

tpluscode
Copy link
Contributor

I'm adding one more change before we refactor, to control the kind of module to produce (commonjs, ESM, TypeScript)

  • add module option
  • mention in readme

Comment on lines 27 to 43
let leadingLines
switch (module) {
case 'esm':
leadingLines = ['export const dataset = ({ blankNode, literal, namedNode, quad }) => {']
break
case 'ts':
leadingLines = [
"import { DataFactory, Quad } from 'rdf-js'",
'',
'export const dataset = ({ blankNode, literal, namedNode, quad }: DataFactory): Quad[] => {'
]
break
default:
leadingLines = ['module.exports = ({ blankNode, literal, namedNode, quad }) => {']
break
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to use subclasses to handle this? E.g. TS may also use a different code style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, why not 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of going for subclassing I went for a strategy pattern. For now only the leadingLines but could extract other portions in the future which shall differ between output types

test/test.js Outdated Show resolved Hide resolved
test/test.js Outdated Show resolved Hide resolved
@tpluscode tpluscode requested a review from bergos July 21, 2020 11:37
super({
objectMode: true,
read: () => {}
})

getStream.array(input).then(quads => {
this.push((new PlainSerializer()).transform(quads))
this.push((new PlainSerializer(options)).transform(quads))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I missed this class earlier. You want a test for that?

@bergos bergos merged commit a782136 into rdfjs-base:master Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants