require-from-memory

NodeJs "require" with mock content and file name and supports babel, pirates, etc

Usage no npm install needed!

<script type="module">
  import requireFromMemory from 'https://cdn.skypack.dev/require-from-memory';
</script>

README

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Description

Cross platform NodeJs require with mock content and file name and support babel, pirates, etc

import {requireFromString} from 'require-from-memory'

const myModule = requireFromString(
    'export default { ... }', 
    'fake/path/my-module.js',
    options, // optional
) 

/*
options: {
    logFilter(logEvent): boolean // return false to prevent show log
}

logEvent: {
    level: 'INFO' | 'WARNING' | 'ERROR',
    type: 'FindPath',
    message,
    filename,
    code,
    vars: {
        // additional info
    },
    exception,
}
*/

License

CC0-1.0