# urify

> static analysis for datauri expressions

Latest version **2.1.1** (published 2018-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install urify
pnpm add urify
yarn add urify
bun add urify
```

## 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 | 2.1.1 |
| Published | 2018-08-08 |
| First published | 2014-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | data, uri, datauri, base64, b64, inline, browserify, asset, assets, url |

## Links

- npm: https://www.npmjs.com/package/urify
- Repository: https://github.com/mattdesl/urify
- Issues: https://github.com/mattdesl/urify/issues
- npm.io page: https://npm.io/package/urify

## Dependencies (6)

- [mime](https://npm.io/package/mime.md) ^1.3.4
- [resolve](https://npm.io/package/resolve.md) ^1.1.7
- [from2-string](https://npm.io/package/from2-string.md) ^1.1.0
- [quote-stream](https://npm.io/package/quote-stream.md) ^1.0.2
- [static-module](https://npm.io/package/static-module.md) ^3.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.0.5

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.1.1 (latest) — 2018-08-08
- 2.1.0 — 2016-09-04
- 2.0.2 — 2016-01-24
- 2.0.1 — 2016-01-24
- 2.0.0 — 2016-01-24
- 1.1.1 — 2015-11-13
- 1.1.0 — 2015-07-11
- 1.0.6 — 2014-10-12
- 1.0.5 — 2014-10-12
- 1.0.4 — 2014-10-12
- 1.0.3 — 2014-10-11
- 1.0.2 — 2014-10-11
- 1.0.1 — 2014-10-11
- 1.0.0 — 2014-10-11

## README

# urify

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

A simple module to synchronously return a DataURI for the given file path.

This also includes a browserify transform to statically analyze the expression, inlining the URI during the bundle step. This allows you to do the following in the browser:

```js
var path = require('path');
var urify = require('urify');
var uri = urify(path.join(__dirname, 'icon.png'));

var img = new Image()
img.onload = function() {
  console.log("Image loaded!")
}
img.src = uri
```

While bundling, include the `urify/transform` like so:

```browserify -t urify/transform foo.js > bundle.js```

After bundling, the code will look like this:

```js
var uri = "data:image/png;base64,....."

var img = new Image()
img.onload = function() {
  console.log("Image loaded!")
}
img.src = uri
```

## API Usage

[![NPM](https://nodei.co/npm/urify.png)](https://nodei.co/npm/urify/)

### `urify = require('urify')`
#### `uri = urify(file)`

Synchronously grabs a file's DataURI string, with the following format:

```js
"data:image/png;base64,....."
```

### `transform = require('urify/transform')`
#### `stream = transform(file, [opts])`

Returns a through stream inlining `require('urify')` calls to their statically evaluated DataURI strings. 

Optionally, you can set which `opt.vars` will be used in the [static-eval](https://www.npmjs.org/package/static-eval) in addition to `__dirname` and `___filename`. 

## Upgrade from 1.x to 2.x

There was a signficant breaking change between 1.x and 2.x.  Note the following:

### Specifying what should be urified

`datauri` has been replaced with `urify`.

#### 1.x

```javascript
var datauri = require('datauri');
var data = datauri('path/to/file');
```

#### 2.x

```javascript
var urify = require('urify');
var data = urify('path/to/file');
```

### Specifying Transform

Use `urify/transform` instead of `urify`:

#### 1.x

```json
  "browserify": {
    "transform": [
      "urify"
    ]
  }
```

#### 2.x

```json
  //2.x
  "browserify": {
    "transform": [
      "urify/transform"
    ]
  }
```


## License

MIT, see [LICENSE.md](http://github.com/mattdesl/urify/blob/master/LICENSE.md) for details.

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