2018-09-30 23:01:58 +01:00
---
id: 587d7b8c367417b2b2512b57
title: Use * to Import Everything from a File
challengeType: 1
---
## Description
< section id = 'description' >
2019-04-26 09:03:04 -04:00
Suppose you have a file and you wish to import all of its contents into the current file. This can be done with the < code > import * as< / code > syntax.
2018-09-30 23:01:58 +01:00
Here's an example where the contents of a file named < code > "math_functions"< / code > are imported into a file in the same directory:
< blockquote > import * as myMathModule from "math_functions";< br > myMathModule.add(2,3);< br > myMathModule.subtract(5,3);< / blockquote >
And breaking down that code:
< blockquote > import * as object_with_name_of_your_choice from "file_path_goes_here"< br > object_with_name_of_your_choice.imported_function< / blockquote >
2019-03-07 08:57:43 +09:00
You may use any name following the < code > import * as < / code > portion of the statement. In order to utilize this method, it requires an object that receives the imported values (i.e., you must provide a name). From here, you will use the dot notation to call your imported values.
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
2019-04-26 09:03:04 -04:00
The code in this file requires the contents of another file, < code > "capitalize_strings"< / code > , that is in the same directory as the current file. Add the appropriate < code > import * as< / code > statement to the top of the file.
2018-09-30 23:01:58 +01:00
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
- text: Properly uses < code > import * as</ code > syntax.
2018-10-20 21:02:47 +03:00
testString: assert(code.match(/import\s+\*\s+as\s+[a-zA-Z0-9_$]+\s+from\s*"\s*capitalize_strings\s*"\s*;/gi), 'Properly uses < code > import * as</ code > syntax.');
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
"use strict";
```
< / div >
### Before Test
< div id = 'js-setup' >
```js
2019-01-15 18:29:33 +03:00
self.require = function(str) {
if (str === 'capitalize_strings') {
return {
capitalize: str => str.toUpperCase(),
lowercase: str => str.toLowerCase()
}
}
};
2018-09-30 23:01:58 +01:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-01-15 18:29:33 +03:00
import * as capitalize_strings from "capitalize_strings";
2018-09-30 23:01:58 +01:00
```
2019-01-15 18:29:33 +03:00
2018-09-30 23:01:58 +01:00
< / section >