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

unist-builder

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-builder - npm Package Compare versions

Comparing version 2.0.3 to 3.0.0

index.d.ts

61

index.js

@@ -1,25 +0,46 @@

'use strict'
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Parent} Parent
* @typedef {import('unist').Literal} Literal
* @typedef {Object.<string, unknown>} Props
* @typedef {Array.<Node>|string} ChildrenOrValue
*
* @typedef {(<T extends string, P extends Record<string, unknown>, C extends Node[]>(type: T, props: P, children: C) => {type: T, children: C} & P)} BuildParentWithProps
* @typedef {(<T extends string, P extends Record<string, unknown>>(type: T, props: P, value: string) => {type: T, value: string} & P)} BuildLiteralWithProps
* @typedef {(<T extends string, P extends Record<string, unknown>>(type: T, props: P) => {type: T} & P)} BuildVoidWithProps
* @typedef {(<T extends string, C extends Node[]>(type: T, children: C) => {type: T, children: C})} BuildParent
* @typedef {(<T extends string>(type: T, value: string) => {type: T, value: string})} BuildLiteral
* @typedef {(<T extends string>(type: T) => {type: T})} BuildVoid
*/
module.exports = u
export var u = /**
* @type {BuildVoid & BuildVoidWithProps & BuildLiteral & BuildLiteralWithProps & BuildParent & BuildParentWithProps}
*/ (
/**
* @param {string} type Type of node
* @param {Props|ChildrenOrValue} [props] Additional properties for node (or `children` or `value`)
* @param {ChildrenOrValue} [value] `children` or `value` of node
* @returns {Node}
*/
function (type, props, value) {
/** @type {Node} */
var node = {type: String(type)}
function u(type, props, value) {
var node
if (
(value === undefined || value === null) &&
(typeof props === 'string' || Array.isArray(props))
) {
value = props
} else {
Object.assign(node, props)
}
if (
(value === null || value === undefined) &&
(typeof props !== 'object' || Array.isArray(props))
) {
value = props
props = {}
}
if (Array.isArray(value)) {
node.children = value
} else if (value !== undefined && value !== null) {
node.value = String(value)
}
node = Object.assign({type: String(type)}, props)
if (Array.isArray(value)) {
node.children = value
} else if (value !== null && value !== undefined) {
node.value = String(value)
return node
}
return node
}
)
{
"name": "unist-builder",
"version": "2.0.3",
"version": "3.0.0",
"description": "unist utility to create a new trees with a nice syntax",

@@ -33,31 +33,35 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"types/index.d.ts"
"index.d.ts",
"index.js"
],
"types": "types/index.d.ts",
"dependencies": {},
"dependencies": {
"@types/unist": "^2.0.0"
},
"devDependencies": {
"@types/mdast": "^3.0.0",
"dtslint": "^3.0.0",
"nyc": "^15.0.0",
"prettier": "^1.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
"tape": "^4.0.0",
"xo": "^0.26.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",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"tsd": "^0.14.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test-types": "dtslint types",
"test": "npm run format && npm run test-coverage && npm run test-types"
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && tsd && 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": {

@@ -73,3 +77,8 @@ "tabWidth": 2,

"prettier": true,
"esnext": false
"rules": {
"capitalized-comments": "off",
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},

@@ -80,3 +89,8 @@ "remarkConfig": {

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

@@ -16,2 +16,5 @@ # unist-builder

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

@@ -26,3 +29,3 @@

```js
var u = require('unist-builder')
import {u} from 'unist-builder'

@@ -69,2 +72,5 @@ var tree = u('root', [

This package exports the following identifiers: `u`.
There is no default export.
### `u(type[, props][, children|value])`

@@ -116,5 +122,5 @@

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

@@ -139,5 +145,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-builder.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/syntax-tree
[chat]: https://github.com/syntax-tree/unist/discussions

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

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

@@ -155,0 +161,0 @@ [unist]: https://github.com/syntax-tree/unist

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