# pco-url

> A dumb url origin generator in JS

Latest version **2.0.1** (published 2018-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install pco-url
pnpm add pco-url
yarn add pco-url
bun add pco-url
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-01-19 |
| First published | 2017-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Michael Chan |
| Maintainers | chantastic |

## Links

- npm: https://www.npmjs.com/package/pco-url
- Repository: https://github.com/planningcenter/pco-url
- npm.io page: https://npm.io/package/pco-url

## Recent versions

- 2.0.1 (latest) — 2018-01-19
- 2.0.0 — 2017-12-12
- 1.1.0 — 2017-09-29
- 1.0.1 — 2017-09-29
- 1.0.0 — 2017-07-12

## README

# DEPRECATED:
## USE ORG-SCOPED [@planningcenter/url](https://github.com/planningcenter/javascript/tree/master/packages/url)

# pco-url
A dumb url origin generator in JS.

Builds environment-considered url origins in JS-land, for Planning Center apps.

## Examples
```js
pcoUrl("development")("api")
// => "http://api.pco.test"

pcoUrl("staging")("people")
// => "https://accounts.planningcenteronline.com"

pcoUrl("production")("accounts")
// => "https://people-staging.planningcenteronline.com"
```

Arguments are curried.
You can make a generic env-considered function.

```js
const envPcoUrl = pcoUrl(window.railsEnv)
envPcoUrl("api")
```

## In Planning Center Apps
Planning center apps expose the Rails env as the JS global `railsEnv`. Use like so.

```js
pcoUrl(railsEnv)("api")
```

## Fetching example
```js
fetch(`${pcoEnvUrl(env)("api")}/people/v2/me`, {
  credentials: "include",
})
  .then(res => res.json())
  .then(json => json.data)
  .then(({ id, attributes }) =>
    this.setState({
      currentUser: {
        id,
        ...attributes,
      },
    })
  )
  .catch(err => console.log(err));

```

## Installation
Script tag on Rails
```html
<script type="javascript" src="https://unpkg.com/pco-url@1.0.0/lib/pco-url.js"></script>
<!-- exposed as global `pcoUrl` -->
```

Webpacker on Rails
```bash
yarn add pco-url
```

```js
/* global railsEnv */
import pcoUrl from "pco-url"

pcoUrl(railsEnv)("api")
```

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