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

@tokey/imports-parser

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tokey/imports-parser

parser for esm like imports

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
increased by22.87%
Maintainers
3
Weekly downloads
 
Created
Source

@tokey/imports-parser

Parser for esm like import syntax with support for "functional" tagged imports

import Name1, { Name2, Name3 as Name4, Tag(Name5) } from "request";

The output of parsing an import is represented with the following type:

interface ImportValue {
  star: boolean;
  defaultName: string | undefined;
  named: Record<string, string> | undefined;
  tagged: Record<string, Record<string, string>> | undefined;
  from: string | undefined;
  errors: string[];
  start: number;
  end: number;
}

Notice that this parser can parse broken/incomplete syntax and all the errors will be available in the "error" field.

The parser parses multiple imports and the result is an ImportValue[]

API

import { parseImports, ImportValue } from "@tokey/imports-parser";

const code = `
    import { a } from "request/a";
    import "request/b";
`;
const startNamedBlock = '{'; // default
const endNamedBlock = '}'; // default
const shouldParseTags = false // default

const results: ImportValue[] = parseImports(code, startNamedBlock, endNamedBlock, shouldParseTags);

const firstImport = results[0];
firstImport.from === 'request/a'; // true
firstImport.named['a'] === 'a'; // true

Keywords

FAQs

Package last updated on 14 Dec 2022

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