@a-la/detect-jsx
Detects Position Of JSX Tag In JavaScript File.
Last updated 5 years ago by zvr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @a-la/detect-jsx 
SYNC missed versions from official npm registry.

@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

Copyright

(c) À La Mode 2019

Current Tags

  • 1.0.2                                ...           latest (5 years ago)

3 Versions

  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 0
Dependencies (0)
None
Dev Dependencies (6)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |