Socket
Socket
Sign inDemoInstall

mdast-util-definitions

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-definitions - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

index.d.ts

56

index.js

@@ -1,18 +0,19 @@

'use strict'
/**
* @typedef {import('unist').Node} Node
* @typedef {import('mdast').Definition} Definition
* @typedef {import('unist-util-visit').Visitor<Definition>} DefinitionVisitor
*/
var visit = require('unist-util-visit')
import {visit} from 'unist-util-visit'
module.exports = getDefinitionFactory
var own = {}.hasOwnProperty
// Get a definition in `node` by `identifier`.
function getDefinitionFactory(node, options) {
return getterFactory(gather(node, options))
}
/**
*
* @param {Node} node
*/
export function definitions(node) {
/** @type {Object.<string, Definition>} */
var cache = Object.create(null)
// Gather all definitions in `node`
function gather(node) {
var cache = {}
if (!node || !node.type) {

@@ -24,19 +25,20 @@ throw new Error('mdast-util-definitions expected node')

return cache
return getDefinition
/** @type {DefinitionVisitor} */
function ondefinition(definition) {
var id = normalise(definition.identifier)
if (!own.call(cache, id)) {
var id = clean(definition.identifier)
if (id && !own.call(cache, id)) {
cache[id] = definition
}
}
}
// Factory to get a node from the given definition-cache.
function getterFactory(cache) {
return getter
// Get a node from the bound definition-cache.
function getter(identifier) {
var id = identifier && normalise(identifier)
/**
* Get a node from the bound definition-cache.
*
* @param {string} identifier
* @returns {Definition|null}
*/
function getDefinition(identifier) {
var id = clean(identifier)
return id && own.call(cache, id) ? cache[id] : null

@@ -46,4 +48,8 @@ }

function normalise(identifier) {
return identifier.toUpperCase()
/**
* @param {string} [value]
* @returns {string}
*/
function clean(value) {
return String(value || '').toUpperCase()
}
{
"name": "mdast-util-definitions",
"version": "4.0.0",
"version": "5.0.0",
"description": "mdast utility to find definition nodes in a tree",

@@ -29,39 +29,36 @@ "license": "MIT",

],
"types": "types/index.d.ts",
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"types",
"index.d.ts",
"index.js"
],
"dependencies": {
"unist-util-visit": "^2.0.0"
"@types/mdast": "^3.0.0",
"@types/unist": "^2.0.0",
"unist-util-visit": "^3.0.0"
},
"devDependencies": {
"@types/mdast": "^3.0.0",
"browserify": "^16.0.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark": "^12.0.0",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"remark": "^13.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"xo": "^0.33.0"
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . --write && xo --fix --ignore types",
"build-bundle": "browserify . -s mdastUtilDefinitions > mdast-util-definitions.js",
"build-mangle": "browserify . -s mdastUtilDefinitions -p tinyify > mdast-util-definitions.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -77,7 +74,7 @@ "tabWidth": 2,

"prettier": true,
"esnext": false,
"ignore": [
"types",
"mdast-util-definitions.js"
]
"rules": {
"capitalized-comments": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},

@@ -88,3 +85,8 @@ "remarkConfig": {

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

@@ -17,2 +17,5 @@ # mdast-util-definitions

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][]:

@@ -24,20 +27,14 @@

[npm][] with [TypeScript][] support:
```sh
npm install mdast-util-definitions @types/mdast
```
## Use
```js
var remark = require('remark')
var definitions = require('mdast-util-definitions')
import remark from 'remark'
import {definitions} from 'mdast-util-definitions'
var ast = remark().parse('[example]: https://example.com "Example"')
var tree = remark().parse('[example]: https://example.com "Example"')
var definition = definitions(ast)
var definition = definitions(tree)
definition('example')
// => {type: 'definition', 'title': 'Example', ...}
// => {type: 'definition', 'title': 'Example', …}

@@ -50,2 +47,5 @@ definition('foo')

This package exports the following identifiers: `definitions`.
There is no default export.
### `definitions(tree)`

@@ -100,5 +100,5 @@

[build-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-definitions.svg
[build-badge]: https://github.com/syntax-tree/mdast-util-definitions/workflows/main/badge.svg
[build]: https://travis-ci.org/syntax-tree/mdast-util-definitions
[build]: https://github.com/syntax-tree/mdast-util-definitions/actions

@@ -133,4 +133,2 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-definitions.svg

[typescript]: https://www.typescriptlang.org/
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md

@@ -137,0 +135,0 @@

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