New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

relative-cjs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relative-cjs

Calculate relative path for commonJs require function

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

relative-cjs

Calculate relative path for ES Module import, commonJs require function

Install

Install with npm:

npm install relative-cjs

Install with yarn:

yarn add relative-cjs

Motivation

  • Very often we need to calculate relative path between two modules to generate CJS require function or ESM import statements.

  • This is obivious case when you are generating dynamic code or runtime for webpack plugins.
    Consider an example where you want to generate CSS stylesheet dynamically with url() function pointing to real files.

  • Path to require function or import statement must always start with '.' or '..'

  • This module is extends Jon Schlinkert's relative module and adds '.' or '..' appropriately

Usage


    var relativeCjs = require('relative-cjs');

    relativeCjs('a/b/', 'a');
    // ..

    relativeCjs('./app', './app');
    // ./.

    relativeCjs('./a/b.test/', 'a/c'); // b.test being treated as dir, read relative module doc for more info
    // ../c

    relativeCjs('./a/b.test', 'a/c'); // b.test being treated as file, read relative module doc for more info
    // ./c

Found an issue

Please go through relative documentation once. If issue still persists or feature requests, consider opening a new issue

Keywords

FAQs

Package last updated on 23 Jan 2020

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