Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

retext-pos

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retext-pos - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

86

index.js

@@ -1,58 +0,50 @@

'use strict'
import {visit, SKIP} from 'unist-util-visit'
import {toString} from 'nlcst-to-string'
// @ts-expect-error: untyped.
import posjs from 'pos'
var visit = require('unist-util-visit')
var toString = require('nlcst-to-string')
var posjs = require('pos')
const tagger = new posjs.Tagger()
module.exports = pos
/**
* Plugin to add part-of-speech (POS) tags.
*
* @type {import('unified').Plugin<[]>}
*/
export default function retextPos() {
/**
* @typedef {import('unist').Parent} Parent
* @typedef {import('unist').Node} Node
*/
return (tree) => {
visit(tree, 'SentenceNode', (/** @type {Parent} */ node) => {
const children = node.children
/** @type {Node[]} */
const words = []
let index = -1
var tagger = new posjs.Tagger()
// Find words.
while (++index < children.length) {
const child = children[index]
function pos() {
return transformer
}
function transformer(tree) {
visit(tree, 'SentenceNode', visitor)
// Patch all words in `parent`.
function visitor(node) {
var children = node.children
var length = children.length
var index = -1
var values = []
var words = []
var child
var tags
// Find words.
while (++index < length) {
child = children[index]
if (child.type === 'WordNode') {
values.push(toString(child))
words.push(child)
if (child.type === 'WordNode') {
words.push(child)
}
}
}
// Apply tags if there are words.
if (values.length !== 0) {
tags = tagger.tag(values)
length = tags.length
index = -1
// Apply tags if there are words.
if (words.length > 0) {
const tags = tagger.tag(words.map((node) => toString(node)))
index = -1
while (++index < length) {
patch(words[index], tags[index][1])
while (++index < tags.length) {
const node = words[index]
const data = node.data || (node.data = {})
data.partOfSpeech = tags[index][1]
}
}
}
// Don’t enter sentences.
return visit.SKIP
// Don’t enter sentences.
return SKIP
})
}
// Patch a `partOfSpeech` property on `node`s.
function patch(node, tag) {
var data = node.data || (node.data = {})
data.partOfSpeech = tag
}
}
{
"name": "retext-pos",
"version": "3.0.0",
"version": "4.0.0",
"description": "retext plugin to add part-of-speech (POS) tags",

@@ -27,38 +27,38 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"nlcst-to-string": "^2.0.0",
"nlcst-to-string": "^3.0.0",
"pos": "^0.4.2",
"unist-util-visit": "^2.0.0"
"unified": "^10.0.0",
"unist-util-visit": "^3.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"nyc": "^15.0.0",
"prettier": "^1.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
"retext": "^7.0.0",
"tape": "^4.0.0",
"tinyify": "^2.0.0",
"unist-builder": "^2.0.0",
"unist-util-remove-position": "^2.0.0",
"xo": "^0.27.0"
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"retext": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"unist-util-remove-position": "^4.0.0",
"xo": "^0.42.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"build-bundle": "browserify . -s retextPos > retext-pos.js",
"build-mangle": "browserify . -s retextPos -p tinyify > retext-pos.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js",
"test": "npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -73,7 +73,3 @@ "tabWidth": 2,

"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"retext-pos.js"
]
"prettier": true
},

@@ -84,3 +80,9 @@ "remarkConfig": {

]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -17,2 +17,5 @@ # retext-pos

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
[npm][]:

@@ -27,21 +30,12 @@

```js
var retext = require('retext')
var inspect = require('unist-util-inspect')
var pos = require('retext-pos')
import {retext} from 'retext'
import {inspect} from 'unist-util-inspect'
import retextPos from 'retext-pos'
retext()
.use(pos)
.use(plugin)
.process('I went to the store, to buy 5.2 gallons of milk.', function (err) {
if (err) {
throw err;
}
.use(retextPos)
.use(() => (tree) => {
console.log(inspect(tree))
})
function plugin() {
return transformer
function transformer(tree) {
console.log(inspect(tree))
}
}
.process('I went to the store, to buy 5.2 gallons of milk.')
```

@@ -95,4 +89,7 @@

### `retext().use(pos)`
This package exports no identifiers.
The default export is `retextPos`.
### `unified().use(retextPos)`
Add part-of-speech (POS) tags to [**word**][word]s using

@@ -117,5 +114,5 @@ [`dariusk/pos-js`][posjs] at `node.data.partOfSpeech`.

[build-badge]: https://img.shields.io/travis/retextjs/retext-pos.svg
[build-badge]: https://github.com/retextjs/retext-pos/workflows/main/badge.svg
[build]: https://travis-ci.org/retextjs/retext-pos
[build]: https://github.com/retextjs/retext-pos/actions

@@ -140,5 +137,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/retextjs/retext-pos.svg

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/retext
[chat]: https://github.com/retextjs/retext/discussions

@@ -149,7 +146,7 @@ [npm]: https://docs.npmjs.com/cli/install

[contributing]: https://github.com/retextjs/.github/blob/master/contributing.md
[contributing]: https://github.com/retextjs/.github/blob/HEAD/contributing.md
[support]: https://github.com/retextjs/.github/blob/master/support.md
[support]: https://github.com/retextjs/.github/blob/HEAD/support.md
[coc]: https://github.com/retextjs/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/retextjs/.github/blob/HEAD/code-of-conduct.md

@@ -156,0 +153,0 @@ [license]: license

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc