# pocketwrench

> An eclectic collection of JavaScript utilities

Latest version **0.0.2** (published 2014-12-31) · LGPLv3 license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2014-12-31 |
| First published | 2014-08-12 |
| Weekly downloads | 0 |
| License | LGPLv3 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tophatsteve |
| Maintainers | tophatsteve |
| Keywords | utility |

## Links

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

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2014-12-31
- 0.0.1 — 2014-08-12

## README

pocketwrench
============

An eclectic collection of JavaScript utilities

[![Build Status](https://travis-ci.org/tophatsteve/pocketwrench.svg?branch=master)](https://travis-ci.org/tophatsteve/pocketwrench)
[![Coverage Status](https://img.shields.io/coveralls/tophatsteve/pocketwrench.svg)](https://coveralls.io/r/tophatsteve/pocketwrench?branch=master)


### Module Overview

Pocketwrench is a collection of JavaScript utility functions that I've found useful over the years. The collection is pretty eclectic, and reflects the various problems
I've needed to solve on a bunch of different projects. The functions are split into different namespaces dependent on what they cover. For example, there is an 'array'
namespace containing all the functions that operate on arrays. I've not attached any new functions to the built in object prototypes because the
functions are often only applicable in certain circumstances.

The namespaces are:

- [array](#array-namepace) - Utility functions that operate on arrays of objects.
- [browser](#browser-namespace) - Functions to aid interaction with the browser.
- [math](#math-namespace) - Mathematical functions.
- [object](#object-namespace) - Utility functions that operate on objects.

### Usage

#### array Namespace

##### findFirstByField(array, fieldName, valueToSearchFor)

Find the first occurrence of an object with key *fieldName* and value *valueToSearchFor*.

```javascript
var pocketwrench = require('pocketwrench');

var testCollection = [
  {name: 'Fred', age: 25},
  {name: 'Bob', age: 40},
  {name: 'Sally', age: 42},
  {name: 'Alice', age: 34},
  {name: 'Jane', age: 25}
];

pocketwrench.array.findFirstByField(testCollection, 'name', 'Sally');

==> {name: 'Sally', age: 42}
```

##### findByField(array, fieldName, valueToSearchFor)

Find all the objects with a key *fieldName* that have a value *valueToSearchFor*.

```javascript
pocketwrench.array.findFirstByField(testCollection, 'age', 25);

==> [{name: 'Fred', age: 25}, {name: 'Jane', age: 25}]
```
##### findFirstIndexByField(array, fieldName, valueToSearchFor)

Find the index of the first occurrence of an object with key *fieldName* and value *valueToSearchFor*.

```javascript
pocketwrench.array.findFirstIndexByField(testCollection, 'name', 'Sally');

==> 2
```

##### sortByField(array, fieldName, desc)

Sort an array of objects by attribute *fieldName*. *desc* is a boolean indicating the sort direction, true sorts
descending, false (or omitting the argument altogeter) sorts ascending.

```javascript
pocketwrench.array.sortByField(testCollection, 'name', false);

==> [
    {name: 'Alice', age: 34},
    {name: 'Bob', age: 40},
    {name: 'Fred', age: 25},
    {name: 'Jane', age: 25},
    {name: 'Sally', age: 42}
  ];
```

##### mostFrequentElement(collection, fieldName)

Find the most frequency occurring value for *fieldName*.

```javascript
pocketwrench.array.mostFrequentElement(testCollection, 'age')

==> 25
```

##### countOccurrences(collection, fieldName, value)

Count the number of times *value* occurrs in *fieldName*.

```javascript
pocketwrench.array.countOccurrences(testCollection, 'age', 25)

==> 2
```

##### uniqueValuesByField(collection, fieldName)

Return a list of unique values in *fieldName*.

```javascript
pocketwrench.array.uniqueValuesByField(testCollection, 'age')

==> [25, 40, 42, 34]
```

##### uniqueValues(collection)

Return a list of unique values in a simple array.

```javascript
pocketwrench.array.uniqueValues([1, 2, 1, 3, 2, 4, 2, 5, 1])

==> [1, 2, 3, 4, 5]
```

#### browser Namespace

##### getQuerystringValues()

Gets the query string as an object.

```javascript
pocketwrench.browser.getQuerystringValues()

==> {
  'key1' : 'value1',
  'key2' : 'value2',
  'key3' : 'value3'
}
```

##### getQuerystringValue(keyName)

Get the value from the query string that corresponds to *keyName*.

```javascript
pocketwrench.browser.getQuerystringValue('key1')

==> 'value1'
```

#### math Namespace

##### logx(number, base)

Return the log of *number* to the base *base*.

```javascript
pocketwrench.math.logx(8, 2)

==> 3
```

#### object Namespace

##### isDictionary(obj)

Returns true if *obj* is a dictionary, otherwise returns false.

```javascript
pocketwrench.object.isDictionary([1,2,3])

==> false

pocketwrench.object.isDictionary({ 'a' : 1, 'b' : 2 })

==> true
```

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