
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@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
The npm package @types/module-alias receives a total of 106,777 weekly downloads. As such, @types/module-alias popularity was classified as popular.
We found that @types/module-alias demonstrated a not healthy version release cadence and project activity because the last version was released 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.