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

@a-la/detect-jsx

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@a-la/detect-jsx

Detects Position Of JSX Tag In JavaScript File.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55
increased by1000%
Maintainers
1
Weekly downloads
 
Created
Source

@a-la/detect-jsx

npm version

@a-la/detect-jsx Detects Position Of JSX Tag In JavaScript File.

yarn add -E @a-la/detect-jsx

Table Of Contents

API

The package is available by importing its default function:

import detectJsx from '@a-la/detect-jsx'

detectJsx(
  string: string,
): number

Returns the position of the first JSX tag by evaluating the code using Node's vm package: since JSX reference will throw an error, this error can be caught and used to find out the index of the opening < symbol in JSX.

For example, given the following JSX component:

const Component = ({ example }) => (
  <div class="Test" id={example}></div>
)

It is possible to detect where JSX starts:

/* yarn example/ */
import read from '@wrote/read'
import detectJSX from '@a-la/detect-jsx'

(async () => {
  const code = await read('example/Component.jsx')
  const res = detectJSX(code)
  console.log(res)
})()
39

(c) À La Mode 2019

Keywords

FAQs

Package last updated on 03 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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