An open API service indexing awesome lists of open source software.

https://github.com/stealjs/steal-fuzzy-normalize

Try to normalize a module identifier given a set of possible module names. Match to the closest result possible.
https://github.com/stealjs/steal-fuzzy-normalize

Last synced: 3 months ago
JSON representation

Try to normalize a module identifier given a set of possible module names. Match to the closest result possible.

Awesome Lists containing this project

README

        

# steal-fuzzy-normalize

[![Build Status](https://travis-ci.org/stealjs/steal-fuzzy-normalize.svg?branch=master)](https://travis-ci.org/stealjs/steal-fuzzy-normalize)
[![npm version](https://badge.fury.io/js/steal-fuzzy-normalize.svg)](http://badge.fury.io/js/steal-fuzzy-normalize)
[![Greenkeeper badge](https://badges.greenkeeper.io/stealjs/steal-fuzzy-normalize.svg)](https://greenkeeper.io/)

**steal-fuzzy-normalize** is a module that tries its hardest to normalize a module identifier given the normal steal rules. It's imperfect, but if you give it a list of possible matches it might just work.

## Install

```
npm install steal-fuzzy-normalize --save
```

## Examples

Getting a match from an array.

```js
var normalize = require("steal-fuzzy-normalize");

var possibilities = [
"[email protected]#home/home",
"[email protected]#orders/orders",
"[email protected]#cart/cart"
];

var match = normalize("orders/", possibilities);

assert.equal(match, "[email protected]#orders/orders"); // Works
```

Getting a match from an object. This allows you to get metadata for a particular match (useful for bundle manifests).

```js
var normalize = require("steal-fuzzy-normalize");

var possibilities = {
"[email protected]#home/home": {page:"home"},
"[email protected]#orders/orders": {page:"orders"},
"[email protected]#cart/cart": {page:"cart"}
};

var match = normalize("orders/", possibilities);

assert.equal(match.page, "orders"); // Works
```