Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @make-mjs/url with all npm packages installed. Try it out:

var url = require("@make-mjs/url")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@make-mjs/url v0.2.8

Manipulate MJS module url

@make-mjs/url

Manipulate MJS module URL

APIs Documentation

Go to the GitHub page

Examples

Internal Modules

import getMjsUrl from '@make-mjs/url'

const mjsPath: string = await getMjsUrl({
  modulePath: './foo/bar/baz', // leading '.' or '..' is required to be recognized as internal
  /* ...and more options... */
})

Result:

  • If ./foo/bar/baz points to a directory without a package.json, mjsPath would be ./foo/bar/baz/index.mjs.
  • If ./foo/bar/baz does not point to a directory, mjsPath would be ./foo/bar/baz.mjs.
  • For other cases, read the tests.

External Modules

import getMjsUrl from '@make-mjs/url'

const mjsPath: string = await getMjsUrl({
  modulePath: 'foo/bar/baz',
  moduleContainer: [
    'node_modules'
  ],
  /* ...and more options... */
})

Result:

  • If node_modules/foo/bar/baz points to a directory without a package.json, mjsPath would be foo/bar/baz/index.mjs.
  • If node_modules/foo/bar/baz points to a directory that contains a package.json that have "module" points to module.mjs, mjsPath would be foo/bar/baz/module.mjs.
  • If node_modules/foo/baz.js points to a file, mjsPath would be foo/bar/baz.mjs.
  • For other cases, read the tests.

License

MIT © Hoàng Văn Khải

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free