# to-key

> Stringify any value to be used as the key of an object.

Latest version **1.0.0** (published 2015-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-key
pnpm add to-key
yarn add to-key
bun add to-key
```

## 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 | 2015-02-17 |
| First published | 2015-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | cache, key, object, property, string, stringify, to, to-string, tostring |

## Links

- npm: https://www.npmjs.com/package/to-key
- Repository: https://github.com/jonschlinkert/to-key
- Issues: https://github.com/jonschlinkert/to-key/issues
- npm.io page: https://npm.io/package/to-key

## Dependencies (3)

- [for-in](https://npm.io/package/for-in.md) ^0.1.3
- [arr-map](https://npm.io/package/arr-map.md) ^1.0.0
- [kind-of](https://npm.io/package/kind-of.md) ^1.1.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-02-17

## README

# to-key [![NPM version](https://badge.fury.io/js/to-key.svg)](http://badge.fury.io/js/to-key)

> Convert any value to a string that can be used as the key of an object.

## Install with [npm](npmjs.org)

```bash
npm i to-key --save
```

## Usage

```js
var toKey = require('to-key');

toKey({foo: ['bar', {baz: {fex: 'fex'}}], one: 'two'});
//=> 'foobarbazfexfexonetwo'
```

This can be used for caching results when the results are predictable based on user input or other settings.

**Example**

We'll assume that `someFn` in the example does some heavy processing on whatever arguments are passed that can be avoided if we can instead return the cached value of a previous call.

```js
var cache = {};
function myApp(one, two, three) {
  var key = toKey([].slice.call(arguments));
  if (cache.hasOwnProperty(key)) {
    return cache[key];
  }

  var result = someFn(one, two, three);
  cache[key] = result;
  return result;
}
```

**Why do this?**

Given the following:

- `A` is time it takes (to-key or whatever you use) to stringify any arguments are passed
- `B` is the amount of time it takes to retrieve a stored value from the cache 
- `C` is the time it takes your application to process arguments and store a new value on the cache

It's a good approach when `(A + B) < C`. In my applications. You can also use logic that conditionally uses cached results based on the complexity of the arguments passed. 

## Run tests

Install dev dependencies:

```bash
npm i -d && npm test
```

## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/to-key/issues)

## Author

**Jon Schlinkert**
 
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 

## License
Copyright (c) 2015 Jon Schlinkert  
Released under the MIT license

***

_This file was generated by [verb](https://github.com/assemble/verb) on February 16, 2015._

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