# inline-svg-register

> A node require() hook that adds inlining support for SVGs.

Latest version **1.0.0** (published 2016-07-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install inline-svg-register
pnpm add inline-svg-register
yarn add inline-svg-register
bun add inline-svg-register
```

## 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.0 |
| Published | 2016-07-19 |
| First published | 2016-07-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Chris Mendis |
| Maintainers | chrismendis |
| Keywords | node, svg, require |

## Links

- npm: https://www.npmjs.com/package/inline-svg-register
- Repository: https://github.com/chrismendis/inline-svg-register
- Homepage: https://github.com/chrismendis/inline-svg-register#readme
- Issues: https://github.com/chrismendis/inline-svg-register/issues
- npm.io page: https://npm.io/package/inline-svg-register

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [babel-register](https://npm.io/package/babel-register.md) ^6.9.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-07-19
- 0.0.1 — 2016-07-19

## README

# inline-svg-register

`babel-register` for SVG files.™

[![Build Status](https://travis-ci.org/chrismendis/inline-svg-register.svg?branch=master)](https://travis-ci.org/chrismendis/inline-svg-register)

## Installation

```npm install --save-dev inline-svg-register```

## Usage

### Registering the SVG `require()` hook

`require("inline-svg-register")` in any file, as long as it comes before you `require()` any SVG files.

#### Example

```javascript
require("inline-svg-register");
var svg = require("./my-cool.svg");
```

### Unregistering the SVG `require()` hook

`inline-svg-register`'s export is a function that, when called, will unregister the `require()` hook that it added.

#### Example

```javascript
var unhook = require("inline-svg-register");
var svg = require("./my-cool.svg");
unhook();
```

## Motivation

Imagine that you have a Webpack-bundled JavaScript app that uses the [`raw-loader`](https://github.com/webpack/raw-loader) to `require()` in SVG file contents as a string.

You also have a very simple [`tape`](https://github.com/substack/tape) test setup that just `require()`s in whatever files that you want to test.

If you try to test any files that contain `require()` calls to SVG files, node will throw a parsing error on those calls because node expects *only* JavaScript files to be passed to `require()`.

CoffeeScript and Babel both get around this constraint by extending node's file type support using a deprecated feature: [`require.extensions`](https://nodejs.org/api/globals.html#globals_require_extensions). This feature allows node to compile CoffeeScript or ES2015 on-the-fly to JavaScript that node can parse. I adapted Babel's solution, called [`babel-register`](https://github.com/babel/babel/tree/master/packages/babel-register), to compile an SVG file on-the-fly to a JavaScript string.

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