0.0.20 • Published 2 years ago
extract-modules v0.0.20
extract-modules
Parses the string to get its body and location information
Usage
parseImports(code)
import { parseImports } from 'extract-modules' parseImports(` import a from 'b'; import 'extract-modules'; import { c } from "d" `) /** output [ { text: "import a from 'b';", start: 5, end: 23, import: 'a', from: 'b', extra: { import: {start:12,end:13}, from: {start:20,end:21} } }, { text: "import 'extract-modules';", start: 28, end: 53, import: undefined, from: 'extract-modules', extra: { import: null, from: {start:36,end:51} } }, { text: 'import { c } from "d"', start: 58, end: 79, import: ' c ', from: 'd', extra: { import: {start:66,end:69}, from: {start:77,end:78} } } ] */
parseExports(code)
import { parseExports } from 'extract-modules' parseExports(` export const a =
function(){
alert(1)
}
export let h = ()=>{
}
export let c = function(){
}
export const a =
()=>{
console.log(1)
}
export default {
a,
b:1,
c:{
d:1
}
}
export function c(){
const a = 1;
const _b = ()=>{
console.log(1)
}
};
export let a
export let b = 1;
export let d = {
a:1,
b:{
c:{
d:2
}
}
}
* parseVariables(code)
```js
import { parseVariables } from 'extract-modules'
parseVariables(`
const a = 1;
let b = 1
const c = {
}
const d = {
c:{
}
}
const {e} = {
e:1
}
const f =
{
f:{
f2:2
}
}
const h = function(){
console.log(1)
}
`)
/** output
[
{
end:18
key:'a'
start:0
text:'const a = 1;'
value:'1;'
},
...
end:188
key:'f'
start:130
text:'const f = \n {\n f:{\n f2:2\n }\n }'
value:'{\n f:{\n f2:2\n }\n }'
]
*/
parseFunctions(code,start,end)
import { parseFunctions } from 'extract-modules' parseFunctions(` const b = function(){ console.log('b') } function a(){ } const c = ()=>{ } const d = ()=>{ } `) /** output [ { end:56 start:0 text:'const b = function(){\n console.log('b')\n }' }, ... { end:146 start:108 text:'const d = \n ()=>{\n \n }' } ] */
parseComments(code)
import { parseComments } from 'extract-modules' parseComments(` <div></div> <script> // aaaannnn /** * a:1 * b:{ * c:1 * } * * */ </script> <script lang='ts'> /** * a2:1 * b2:{ * c2:1 * } */ </script> `) /** output [ { end:37, start:25, text:'// aaaannnn\n', type:'single', jsonText:{ value:"aaaannnn" } }, { end:79, jsonText:{a: 1, b: { c:1 }}, start:38 text:'/**\n * a:1\n * b:{\n * c:1\n * }\n *\n * \n */' type:'multiple' } ] */
parseAny(code,start,end)
import {parseAny} from 'extract-modules' parseAny('123jmn456','3','4') /** output { start:2, end:7, text:'3jmn4' } */
0.0.20
2 years ago
0.0.19
2 years ago
0.0.18
2 years ago
0.0.17
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago
0.0.14
2 years ago
0.0.13
2 years ago
0.0.12
2 years ago
0.0.11
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago
0.0.0
2 years ago