Socket
Book a DemoInstallSign in
Socket

load-alias

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-alias

This module requires files via aliases

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

Install

npm install load-alias

About

This module requires files via aliases

Example

const LoadAlias = require('load-alias');

const loadConfig = {
  public: 'public/',
  css: '@public/css/',
  img: '@public/img/',
  favicon: '@img/favicon.ico',
  db: 'db/',
  dbModels: '@db/models/',
  upload: 'upload/',
  test: function (alias, replacement) {
	  return 'some/thing';
  }	
}

const alias = new LoadAlias(loadConfig); // or new loadAlias(rootPath, loadConfig) 

let modelUser = alias.load('@dbModels/user.js');
let imgAvatarPath = alias.getPath('@img/avatar.png');  // => 'public/img/avatar.png'
let imgAvatarFullPath = alias.getFullPath('@img/avatar.png'); // => alias.rootPath + '/public/img/avatar.png'
let path = alias.require('path'); // gets nodejs path library
let something = alias.require('./relative/path/'); // doesn't merge with .rootPath

Root path

The default alias.rootPath = process.cwd()
But you can change it: alias.rootPath = something

Api

.load(path)

Loading file using a full path

.require(path)

Loading file using a relative path.

.getConfig()

Getting the config

.setConfig(config)

Config will be merged with the current

.get(name)

Getting the alias

.set(name, alias)

Adding or updating the alias

.del(name)

Deleting the alias

.getPath(path)

Getting transformed path without .rootPath

.getFullPath(path)

Getting the full transformed path including .rootPath

Keywords

load

FAQs

Package last updated on 03 Feb 2022

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