Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@types/module-alias
Advanced tools
TypeScript definitions for module-alias
@types/module-alias is a TypeScript type definition package for the module-alias library, which allows you to create custom module paths and aliases in Node.js applications. This can help simplify and organize your import statements, making your codebase cleaner and more maintainable.
Registering Aliases
This feature allows you to register custom aliases for your modules. In this example, '@root' is aliased to the root directory and '@models' is aliased to the models directory.
const moduleAlias = require('module-alias');
moduleAlias.addAlias('@root', __dirname);
moduleAlias.addAlias('@models', __dirname + '/models');
Using Aliases in Imports
Once aliases are registered, you can use them in your import statements. This makes your import paths shorter and more readable.
const myModel = require('@models/myModel');
Configuration via package.json
You can also configure your aliases directly in your package.json file. This provides a centralized place for managing your module aliases.
{
"_moduleAliases": {
"@root": ".",
"@models": "models"
}
}
tsconfig-paths is a package that helps load modules whose location is specified in the paths section of tsconfig.json. It is specifically designed for TypeScript projects and provides similar functionality to module-alias by allowing you to define custom module paths.
babel-plugin-module-resolver is a Babel plugin that allows you to add custom module resolution paths, similar to module-alias. It is more commonly used in projects that use Babel for transpilation and offers more flexibility with Babel's ecosystem.
npm install --save @types/module-alias
This package contains type definitions for module-alias (https://github.com/ilearnio/module-alias/).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/module-alias.
// Type definitions for module-alias 2.0
// Project: https://github.com/ilearnio/module-alias/
// Definitions by: Kevin Ramharak <https://github.com/KevinRamharak>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = init;
/**
* Import aliases from package.json
*/
declare function init(options?: string | init.Options): void;
/**
* Exported functoins
*/
declare namespace init {
function isPathMatchesAlias(path: string, alias: string): boolean;
/**
* Register a custom modules directory
*/
function addPath(path: string): void;
/**
* Register a single alias
*/
function addAlias(alias: string, path: string): void;
/**
* Register mutliple aliases
*/
function addAliases(aliases: { [alias: string]: string }): void;
/**
* Reset any changes maded (resets all registered aliases
* and custom module directories)
* The function is undocumented and for testing purposes only
*/
function reset(): void;
/**
* module intialis options type
*/
interface Options {
base: string;
}
}
These definitions were written by Kevin Ramharak.
FAQs
TypeScript definitions for module-alias
We found that @types/module-alias demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.