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

mlly

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mlly - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

### [0.1.6](https://github.com/unjs/mlly/compare/v0.1.5...v0.1.6) (2021-07-23)
### Features
* json support ([81c12af](https://github.com/unjs/mlly/commit/81c12af219abc7b86cc551605e8eace96debb497))
### Bug Fixes
* resolve bug fixes ([e5946df](https://github.com/unjs/mlly/commit/e5946df14ebdcc994a2f464c07a5439b67359559))
### [0.1.5](https://github.com/unjs/mlly/compare/v0.1.4...v0.1.5) (2021-07-22)

@@ -7,0 +19,0 @@

7

lib/index.d.ts

@@ -31,6 +31,5 @@ // CommonJS

export function loadModule (id: string, opts?: EvaluateOptions) : Promise<any>
export function loadModule (url: string, opts?: EvaluateOptions) : Promise<any>
export function evalModule (code: string, opts?: EvaluateOptions) : Promise<any>
export function readModule (id: string, opts?: EvaluateOptions) : Promise<{ url: string, code: string}>
export function toDataURL(code: string, opts?: EvaluateOptions) : Promise<string>
export function transformModule(code: string, opts?: EvaluateOptions) : Promise<string>

@@ -41,1 +40,3 @@ // Utils

export function normalizeid (id: URL | string) : string
export function loadURL (id: string) : Promise<string>
export function toDataURL(code: string) : string
{
"name": "mlly",
"version": "0.1.5",
"version": "0.1.6",
"description": "Missing ECMAScript module utils for Node.js",

@@ -5,0 +5,0 @@ "repository": "unjs/mlly",

@@ -105,17 +105,5 @@ # 🤝 mlly

### `loadModule`
Dynamically loads a module by evaluating source code.
```js
import { loadModule } from 'mlly'
await loadModule('./hello.mjs', { from: import.meta.url })
```
Options are same as `evalModule`.
### `evalModule`
Evaluates JavaScript module code using dynamic imports with [`data:`](https://nodejs.org/api/esm.html#esm_data_imports) using `toDataURL`.
Transform and evaluates module code using dynamic imports.

@@ -135,35 +123,25 @@ ```js

- [all `resolve` options]
- all `resolve` options
- `url`: File URL
### `readModule`
### `loadModule`
Resolve module path and read source contents. (currently only file protocol supported)
Dynamically loads a module by evaluating source code.
```js
import { resolve, readModule } from 'mlly'
import { loadModule } from 'mlly'
const indexPath = await resolve('./index.mjs', { from: import.meta.url })
// { code: '...", url: '...' }
console.log(await readModule(indexPath))
await loadModule('./hello.mjs', { from: import.meta.url })
```
Options are same as `resolve`.
Options are same as `evalModule`.
### `toDataURL`
### `transformModule`
Convert code to [`data:`](https://nodejs.org/api/esm.html#esm_data_imports) URL using base64 encoding.
- Resolves all relative imports will be resolved
- All usages of `import.meta.url` will be replaced with `url` or `from` option
All relative imports will be automatically resolved with `from` param using `resolveImports`.
If `url` option is provided, all usages of `import.meta.url` will be rewritten too.
```js
import { toDataURL } from 'mlly'
console.log(await toDataURL(`
// This is an example
console.log('Hello world')
`))
console.log(transformModule(`console.log(import.meta.url)`), { url: 'test.mjs' })
```

@@ -173,4 +151,5 @@

## Other utils
## Other Utils
### `fileURLToPath`

@@ -201,4 +180,28 @@

### `loadURL`
Read source contents of a URL. (currently only file protocol supported)
```js
import { resolve, loadURL } from 'mlly'
const url = await resolve('./index.mjs', { from: import.meta.url })
console.log(await loadURL(url))
```
### `toDataURL`
Convert code to [`data:`](https://nodejs.org/api/esm.html#esm_data_imports) URL using base64 encoding.
```js
import { toDataURL } from 'mlly'
console.log(toDataURL(`
// This is an example
console.log('Hello world')
`))
```
## License
MIT

Sorry, the diff of this file is not supported yet

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