# link-to-func

> router link to function

Latest version **1.0.5** (published 2017-08-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install link-to-func
pnpm add link-to-func
yarn add link-to-func
bun add link-to-func
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2017-08-14 |
| First published | 2017-08-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | hnsylitao |
| Maintainers | hnsylitao |
| Keywords | router, link, to, func |

## Links

- npm: https://www.npmjs.com/package/link-to-func
- Repository: https://hnsylitao@github.com/hnsylitao/link-to-func
- Homepage: https://github.com/hnsylitao/link-to-func#readme
- Issues: https://github.com/hnsylitao/link-to-func/issues
- npm.io page: https://npm.io/package/link-to-func

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2017-08-14
- 1.0.4 — 2017-08-14
- 1.0.3 — 2017-08-14
- 1.0.2 — 2017-08-10
- 1.0.1 — 2017-08-10
- 1.0.0 — 2017-08-10

## README

[![Build Status](https://travis-ci.org/hnsylitao/link-to-func.svg?branch=master)](https://travis-ci.org/hnsylitao/link-to-func)
[![codecov](https://codecov.io/gh/hnsylitao/link-to-func/branch/master/graph/badge.svg)](https://codecov.io/gh/hnsylitao/link-to-func)
[![Version](https://img.shields.io/npm/v/link-to-func.svg?style=flat)](https://www.npmjs.com/package/link-to-func)
[![NPM](https://img.shields.io/npm/dt/link-to-func.svg?style=flat)](https://www.npmjs.com/package/link-to-func)
[![LICENSE](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/hnsylitao/link-to-func/blob/master/LICENSE)

# link-to-func 

router link to function [demo](https://codepen.io/hnsylitao/pen/qXPvVN)

```
npm install link-to-func
```

## Usage

### commonjs
``` js
var LinkToFunc = require('link-to-func')

var absPath = 'https://url.com';

var newsList = LinkToFunc.absPath(absPath, '/home/news/list');
var newsDetail1 = LinkToFunc.absPath(absPath, '/home/news/detail/:id');
var newsDetail2 = LinkToFunc.absPath(absPath, '/home/news(/:id)');

//basic
console.log(newsList()); // /home/news/list
console.log(newsDetail1(1));// /home/news/detail/1
console.log(newsDetail2());// /home/news
console.log(newsDetail2(1));// /home/news/1

//toAbsPath
console.log(newsList.toAbsPath());// https://url.com/home/news/list
console.log(newsDetail1.toAbsPath(1));// https://url.com/home/news/detail/1
console.log(newsDetail2.toAbsPath());// https://url.com/home/news
console.log(newsDetail2.toAbsPath(1));// https://url.com/home/news/1

//getLink
console.log(newsList.getLink());// /home/news/list
console.log(newsDetail1.getLink());// /home/news/detail/:id
console.log(newsDetail2.getLink());// /home/news(/:id)

```

### browser
``` html

<script src="https://unpkg.com/link-to-func/build/index.min.js" type="text/javascript" />
<script type="text/javascript">
  var absPath = 'https://url.com';

  var newsList = linkToFunc.absPath(absPath, '/home/news/list');
  var newsDetail1 = linkToFunc.absPath(absPath, '/home/news/detail/:id');
  var newsDetail2 = linkToFunc.absPath(absPath, '/home/news(/:id)');

  //basic
  console.log(newsList()); // /home/news/list
  console.log(newsDetail1(1));// /home/news/detail/1
  console.log(newsDetail2());// /home/news
  console.log(newsDetail2(1));// /home/news/1

  //toAbsPath
  console.log(newsList.toAbsPath());// https://url.com/home/news/list
  console.log(newsDetail1.toAbsPath(1));// https://url.com/home/news/detail/1
  console.log(newsDetail2.toAbsPath());// https://url.com/home/news
  console.log(newsDetail2.toAbsPath(1));// https://url.com/home/news/1

  //getLink
  console.log(newsList.getLink());// /home/news/list
  console.log(newsDetail1.getLink());// /home/news/detail/:id
  console.log(newsDetail2.getLink());// /home/news(/:id)
</script>

```

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