Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "!" character do in nodejs module names?

I've started using the intern library to write functional tests in js, and I realized that I couldn't understand this syntax:

var assert = require('intern/chai!assert');
var registerSuite = require('intern!object');

What is the purpose of the ! character in the argument of the require() method?

like image 406
gillyb Avatar asked Jan 21 '16 13:01

gillyb


People also ask

What is the at symbol in Node modules?

@gocanto npm packages can have a “scope”, which is a prefix beginning with the @ symbol. It's just a way of name-spacing npm packages.

What does AT symbol mean in NPM install?

Scoped packages in npm are preceded by an '@' symbol. A scope allows you to create a package with the same name as a package created by another user or Org without conflict.


1 Answers

Short answer

It identifies a resource that is part of a plugin.
The structure of the identifier is: [plugin]![resource].

Long answer

In the documentation, you can find that:

Intern is built on top of a standard amd loader, which means that its modules are also normally written in the AMD module format.

That's why and how the require function is actually injected, so it's clear that you are not using the require module provided along with Node.JS.

It states also that:

[AMD format] Allows modules and other assets to be asynchronously or conditionally resolved by writing simple loader plugins

If you follow the link provided with the documentation when it cites the loaders, you find that:

Loader plugins extend an AMD implementation by allowing loading of resources that are not traditional JavaScript dependencies.

In particular, you can find that a dependency has the following form:

[Plugin Module ID]![resource ID]

It goes without saying that the default implementation of the loader you get by using intern adheres to the above mentioned standard.

That said, it follows that, if we consider:

intern/chai!assert

You can read it as inter/chai as plugin module and assert as actually required resource.

The purpose of the ! character in the argument of the require() method is to satisfy the requirements of the syntax used to identify a resource that is itself part of a plugin.

like image 99
skypjack Avatar answered Sep 22 '22 08:09

skypjack