Socket
Book a DemoInstallSign in
Socket

filename-to-module-name

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filename-to-module-name

Get the shortest name file can be required by in Node.js

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

npm

filename-to-module-name

Build Status Dependency Status

Returns the shortest module name for the given filename.

Here is a pseudocode, effectively the inverse of require.resolve algorithm used by Node:

1. If X is a directory,
   a. return basename(X)
   b. STOP
2. Let Y be X with ".js", ".json" or ".node" removed
3. If exists(Y), return basename(X). STOP
4. For E in [".js", ".json", ".node"],
   a. If X ends with E, return basename(Y). STOP
   b. If exists(Y + E), return basename(X). STOP
5. Return basename(X)

Example

var moduleName = require('filename-to-module-name');

moduleName('./index.js');
//=> "index"

API

filenameToModuleName(filename)

Returns the module name. filename should be a name of an existing file or directory.

Install

npm install filename-to-module-name

License

MIT

Keywords

module

FAQs

Package last updated on 02 Apr 2015

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