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

xastscript

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xastscript - npm Package Compare versions

Comparing version 2.1.1 to 3.0.0

index.d.ts

70

index.js

@@ -1,66 +0,6 @@

'use strict'
/**
* @typedef {import('./lib/index.js').XChild}} Child Acceptable child value
* @typedef {import('./lib/index.js').XAttributes}} Attributes Acceptable attributes value.
*/
module.exports = x
// Creating xast elements.
function x(name, attributes) {
var node =
name == null
? {type: 'root', children: []}
: {type: 'element', name: name, attributes: {}, children: []}
var index = 1
var key
if (name != null && typeof name !== 'string') {
throw new Error('Expected element name, got `' + name + '`')
}
// Handle props.
if (attributes) {
if (
name == null ||
typeof attributes === 'string' ||
typeof attributes === 'number' ||
'length' in attributes
) {
// Nope, it’s something for `children`.
index--
} else {
for (key in attributes) {
// Ignore nullish and NaN values.
if (attributes[key] != null && attributes[key] === attributes[key]) {
node.attributes[key] = String(attributes[key])
}
}
}
}
// Handle children.
while (++index < arguments.length) {
addChild(node.children, arguments[index])
}
return node
}
function addChild(nodes, value) {
var index = -1
if (value == null) {
// Empty.
} else if (typeof value === 'string' || typeof value === 'number') {
nodes.push({type: 'text', value: String(value)})
} else if (typeof value === 'object' && 'length' in value) {
while (++index < value.length) {
addChild(nodes, value[index])
}
} else if (typeof value === 'object' && value.type) {
if (value.type === 'root') {
addChild(nodes, value.children)
} else {
nodes.push(value)
}
} else {
throw new TypeError('Expected node, nodes, string, got `' + value + '`')
}
}
export {x} from './lib/index.js'
{
"name": "xastscript",
"version": "2.1.1",
"version": "3.0.0",
"description": "xast utility to create trees",

@@ -28,7 +28,16 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"types/index.d.ts"
"lib/",
"index.d.ts",
"index.js"
],
"types": "types",
"exports": {
".": "./index.js",
"./index.js": "./index.js",
"./jsx-runtime": "./jsx-runtime.js"
},
"dependencies": {

@@ -41,26 +50,28 @@ "@types/xast": "^1.0.0"

"@babel/plugin-transform-react-jsx": "^7.0.0",
"@types/babel__core": "^7.0.0",
"@types/tape": "^4.0.0",
"astring": "^1.0.0",
"buble": "^0.20.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"c8": "^7.0.0",
"estree-util-build-jsx": "^2.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",
"unist-builder": "^2.0.0",
"xo": "^0.36.0"
"tsd": "^0.14.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"xo": "^0.39.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"{script/**,test/**,}*.d.ts\" \"lib/{index,runtime}.d.ts\" && tsc && tsd && type-coverage",
"generate": "node script/generate-jsx",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test-types": "dtslint types",
"test": "npm run generate && npm run format && npm run test-coverage && npm run test-types"
"test-api": "node test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -76,15 +87,5 @@ "tabWidth": 2,

"prettier": true,
"esnext": false,
"rules": {
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"guard-for-in": "off",
"no-eq-null": "off",
"no-self-compare": "off",
"unicorn/prefer-number-properties": "off"
"no-var": "off",
"prefer-arrow-callback": "off"
}

@@ -96,3 +97,8 @@ },

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

@@ -16,2 +16,5 @@ # xastscript

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,4 +29,4 @@

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

@@ -193,4 +196,4 @@ // Children as an array:

```jsx
var u = require('unist-builder')
var x = require('xastscript')
import {u} from 'unist-builder'
import {x} from 'xastscript'

@@ -230,5 +233,4 @@ console.log(

```jsx
/** @jsx x */
/** @jsxFrag null */
var x = require('xastscript')
/** @jsx x @jsxFrag null */
import {x} from 'xastscript'

@@ -246,5 +248,4 @@ console.log(<music />)

```tsx
/** @jsx x */
/** @jsxFrag null */
import * as x from 'xastscript'
/** @jsx x @jsxFrag null */
import {x} from 'xastscript'

@@ -251,0 +252,0 @@ console.log(<music />)

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