# @tomk79/url2link

> It works on browser and converts URLs written on web pages into links.

Latest version **0.1.1** (published 2023-08-21) · 0 weekly downloads

## Install

```sh
npm install @tomk79/url2link
pnpm add @tomk79/url2link
yarn add @tomk79/url2link
bun add @tomk79/url2link
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-08-21 |
| First published | 2023-08-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tomk79 |

## Links

- npm: https://www.npmjs.com/package/@tomk79/url2link
- npm.io page: https://npm.io/package/@tomk79/url2link

## Recent versions

- 0.1.1 (latest) — 2023-08-21
- 0.1.0 — 2023-08-20

## README

# url2link

It works on browser and converts URLs written on web pages into links.


## Install

As an ES Module.

```js
import url2link from "@tomk79/url2link";
```

As external JavaScript file.

```html
<script src="node_modules/@tomk79/url2link/dist/url2link.js"></script>
```


## Usage

```html
<div class="target-elements">
    <p>Convert inline URLs (ex: https://example.com/foo/bar.html ) to links.</p>
</div>

<script src="url2link.js"></script>
<script>
url2link('.target-elements');
</script>
```

to be like this:

```html
<div class="target-elements">
    <p>Convert inline URLs (ex: <a href="https://example.com/foo/bar.html" rel="noopener noreferrer" target="_blank">https://example.com/foo/bar.html</a> ) to links.</p>
</div>
```

## Options

```js
url2link('.target-elements', {
    pattern: /https?\:\/\/(?:[a-zA-Z0-9\.\-\_\%]*(?:\:[a-zA-Z0-9\.\-\_\%]*)?\@)?[a-zA-Z0-9\.\-]+(?:\:[0-9]+)?(?:\/[a-zA-Z0-9\.\-\_\%\/\?\&\=\+\#]*)?/,
    onCreateLink: function($a){
        // The generated A element `$a` is passed.
        // Please process as necessary.
        return $a;
    },
});
```

- `options.pattern`: Regular expression pattern for detecting URLs
- `options.onCreateLink`: Callback function called on link generation


## Change log

### @tomk79/url2link v0.1.1 (2023-08-21)

- Fix: a flaw in URL pattern detection.

### @tomk79/url2link v0.1.0 (2023-08-20)

- Initial Release


## License

MIT License https://opensource.org/licenses/mit-license.php


## Author

- Tomoya Koyanagi <tomk79@gmail.com>
- website: <https://www.pxt.jp/>
- Twitter: @tomk79 <https://twitter.com/tomk79/>

---
_Source: https://npm.io/package/@tomk79/url2link · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
