@peggyjs/from-mem - v3.1.0
    Preparing search index...

    Function export=

    • Import or require the given code from memory. Knows about the different Peggy output formats. Returns the exports of the module.

      Parameters

      • code: string

        Code to import

      • options: FromMemOptions

        Options. Most important is filename.

      Returns Promise<unknown>

      The evaluated code.

      const mjsResult = await fromMem(
      "export default 42",
      {
      filename: "foo.mjs",
      exec: "return IMPORTED.default + arg",
      arg: 3,
      }
      ); // 45
      const cjsResult = await fromMem(
      "module.exports = 42;",
      {
      filename: "foo.cjs",
      exec: "return IMPORTED + arg",
      arg: 3,
      }
      ); // 45
    Index

    Properties

    clearModuleTypeCache: () => void
    guessModuleType: (filename: string) => Promise<ModuleType>

    Type declaration

      • (filename: string): Promise<ModuleType>
      • Figure out the module type for the given file. If no package.json is found, default to "commonjs".

        Parameters

        • filename: string

          Fully-qualified filename to start from.

        Returns Promise<ModuleType>

        On invalid package.json

    isImportSupported: () => boolean

    Type declaration

      • (): boolean
      • Is importing from an ES6 module supported in the current environment?

        Returns boolean