import
fastn
, one module/component can access code from another component by
importing it. To import a module, use the following syntax:-- import: <module-name>
You can do following imports:
fastn
fastn
also provides a way to define
import alias.fastn
fastn
provides a special module called fastn
, which gives you access to
useful package-related variables. You must have noticed that FASTN.ftd
imports
this module. To import the fastn
module in your code, use the following
syntax:fastn
-- import: fastn
string
representing the package name.string
representing the package's website address.bar.ftd
in your fastn
package, named
my-package
, and you want to import it in another module called foo.ftd
. To
import the bar
module in your foo
module, use the following syntax:foo.ftd
-- import: my-package/bar
bar
module from a dependency package called
other-package
in foo
module of your current package, my-package
. To import
the bar module in your foo module, use the following syntax:foo.ftd
-- import: other-package/bar
fastn
package has a special module, assets
importing which you get access
to its variables. These variables contains the reference to the files or fonts
defined in the package.-- import: my-package/assets
The file referring variables are foreign variables, while, fonts are simple variable.
For more information, please visit assets.fastn
, an alias is an alternative name that can be used to refer to an
imported module. Aliases can be helpful in making the code more concise and
readable.fastn
, we can use the as
keyword when importing a
module.
For example, to create an alias mn
for a module called module-name
, we can
write:-- import: module-name as mn
mn
instead of module-name
.fastn
defined aliasfastn
also defines aliases by itself, when we import a module without
specifying an alias using the as
keyword. In this case, the word after the
last slash in the module path becomes the alias. For example:-- import: some/path/to/module
module
.Aliases can be helpful in several ways:
Abbreviation: Aliases can be used to create shorter or more concise names for commonly used or long entities.
Code readability: Aliases can make code more readable and understandable by giving names to modules that more clearly convey their purpose or meaning.
Refactoring: When refactoring code, like changing the dependencies or imported modules. Aliases can be used to keep the original names in use while the code is being updated to use the new names, so the code continues to work while changes are being made.
Reducing name collisions: Aliases can help avoid naming collisions when importing multiple modules with similar or identical names.
Compatibility: Aliases can be used to maintain compatibility with legacy code or other systems that refer to entities by different names. This can make it easier to integrate with external packages or modules that use different naming conventions.