Skip to content

Commit

Permalink
📦 feat(retext-german): add new package for parsing German natural lan…
Browse files Browse the repository at this point in the history
…guage

🔧 chore(retext-german): add .npmrc and tsconfig.json for package configuration

📝 docs(retext-german): add readme.md for package documentation

🎉 init(retext-german): create index.js and lib/index.js for initial package setup

🔧 chore(retext-german): add package.json for package metadata and dependencies
  • Loading branch information
nyxb committed Oct 5, 2023
1 parent 0d7c168 commit 7d28269
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/retext-german/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-scripts=true
package-lock=false
2 changes: 2 additions & 0 deletions packages/retext-german/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Note: types exposed from `index.d.ts`.
export {default} from './lib/index.js'
37 changes: 37 additions & 0 deletions packages/retext-german/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @typedef {import('nlcst').Root} Root
*/

import {ParseGerman} from 'parse-german'

Check failure on line 5 in packages/retext-german/lib/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Cannot find module 'parse-german' or its corresponding type declarations.

Check failure on line 5 in packages/retext-german/lib/index.js

View workflow job for this annotation

GitHub Actions / node

Cannot find module 'parse-german' or its corresponding type declarations.

/**
* Add support for parsing German natural language.
*
* @returns {undefined}
* Nothing.
*/
export default function retextGerman() {
// @ts-expect-error -- TS in JSDoc doesn’t understand `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {import('unified').Processor<Root>} */ (this)

self.parser = parser

/** @type {import('unified').Parser<Root>} */
function parser(value) {
const parser = new ParseGerman()
add(parser.tokenizeParagraphPlugins, self.data('nlcstParagraphExtensions'))
add(parser.tokenizeRootPlugins, self.data('nlcstRootExtensions'))
add(parser.tokenizeSentencePlugins, self.data('nlcstSentenceExtensions'))
return parser.parse(value)
}
}

/**
* @template T
* @param {Array<T>} list
* @param {Array<T> | undefined} values
*/
function add(list, values) {
if (values) list.unshift(...values)
}
66 changes: 66 additions & 0 deletions packages/retext-german/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "retext-german",
"version": "5.0.0",
"description": "retext plugin to parse German prose",
"license": "MIT",
"keywords": [
"concrete",
"cst",
"german",
"language",
"natural",
"parse",
"plugin",
"process",
"retext",
"retext-plugin",
"syntax",
"tree",
"unified"
],
"homepage": "https://github.com/retextjs/retext",
"repository": "https://github.com/retextjs/retext/tree/main/packages/retext-german",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"bugs": "https://github.com/retextjs/retext/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/nlcst": "^2.0.0",
"parse-german": "^0.0.1",
"unified": "^11.0.0"
},
"scripts": {},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-definitions": "off"
}
}
],
"prettier": true
}
}

0 comments on commit 7d28269

Please sign in to comment.