remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/libs/remix-url-resolver/README.md

38 lines
1.3 KiB

6 years ago
## Remix URL resolver engine
6 years ago
`resolve(url, urlHandler)`
Returns `json` object with exact same path as `import` statement.
**Output**
```json
{
6 years ago
content: 'pragma solidity ^0.5.0;\nimport "./mortal.sol";\n\ncontract Greeter is Mortal {\n /* Define variable greeting of the type string */\n string greeting;\n\n /* This runs when the contract is executed */\n constructor(string memory _greeting) public {\n greeting = _greeting;\n }\n\n /* Main function */\n function greet() public view returns (string memory) {\n return greeting;\n }\n}\n',
6 years ago
cleanURL: '../greeter.sol',
type: 'local'
}
```
6 years ago
#### Usage
6 years ago
`resolve(url, urlHandler)` function should be called from within `handleImportCb` function of `solc.compile(input, handleImportCb)`.
```ts
6 years ago
import { RemixURLResolver } from 'remix-url-resolver'
6 years ago
6 years ago
const urlResolver = new RemixURLResolver()
6 years ago
const fileName: string = '../greeter.sol'
6 years ago
urlResolver.resolve(fileName, urlHandler)
6 years ago
.then((sources: object) => {
console.log(sources)
})
.catch((e: Error) => {
throw e
})
```
6 years ago
#### References
* [TypeScript Publishing](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html)
* [DefinitelyTyped 'Create a new package' guide](https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package)