# sutor-tuple

> A tiny tuple implementation.

Latest version **1.2.1** (published 2016-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install sutor-tuple
pnpm add sutor-tuple
yarn add sutor-tuple
bun add sutor-tuple
```

## 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.2.1 |
| Published | 2016-06-03 |
| First published | 2016-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 5.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel Couper |
| Maintainers | dancouper |
| Keywords | es6, es2015, babel, tuple, simple tuple |

## Links

- npm: https://www.npmjs.com/package/sutor-tuple
- Repository: https://github.com/DanCouper/Sutor-Tuple
- Homepage: https://github.com/DanCouper/Sutor-Tuple#readme
- Issues: https://github.com/DanCouper/Sutor-Tuple/issues
- npm.io page: https://npm.io/package/sutor-tuple

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2016-06-03
- 1.1.1 — 2016-06-03
- 1.1.0 — 2016-06-03
- 1.0.0 — 2016-06-02

## README

# Sutor-Tuple

[![Build Status](https://semaphoreci.com/api/v1/dancouper/sutor-tuple/branches/master/badge.svg)](https://semaphoreci.com/dancouper/sutor-tuple)

[![Coverage Status](https://coveralls.io/repos/github/DanCouper/Sutor-Tuple/badge.svg?branch=master)](https://coveralls.io/github/DanCouper/Sutor-Tuple?branch=master)

A tiny tuple implementation in JS, leveraging frozen arrays. May be of some use to someone. Needs work. Won't be terribly efficient. Includes translation to/from dates (that's *dates*, **not** *time* or *datetime*).

## Usage


`npm i --save sutor-tuple` or similar in project route, then just `import Tuple from 'sutor-tuple'` (or some flavour of `require('sutor-tuple')`).

`Tuple()` is a factory function, and does not need to be called with `new`. I can instantiate a tuple from either an array or a list of arguments - `Tuple(1,2,3)` and `Tuple([1,2,3])` are both valid.


## Implementation notes

Arrays are used to represent the Tuples, as opposed to implementing by using Objects with an internal `tuple` property. This allows the tuple object to retain the standard accessor/enumeration methods, and vastly simplified both the implementation of the attached methods and the testing process.

The method used to build the objects is similar to that described by Doug Crockford in [this talk](http://vimeo.com/97419177) (Gist \[*originally by Mattias Petter Johansson*\] [here](https://gist.github.com/DanCouper/8c7807c2ee9b1b907675)). Properties are explicitly defined due to the return statement only returning the current `tuple` array object; I was having issues holding on to the current value (to allow transformation) until I switched to `Object.defineProperties()`.

Array mutator methods will fail (with an error in strict mode; if the module is compiled to ES5 & used under non-strict mode for some reason they will fail without warning). And any attempt to modify the properties directly will fail.

Array enumerator methods will work fine, but note they will act as normal and return Arrays, not Tuples; I didn't think there was much point reimplementing Tuple-specific enumerator methods beyond those included.


##  Static Methods

### `Tuple(...args)`

Returns a frozen Array, representing a Tuple. To construct the Tuple, either an array of values or a list of arguments can be passed.

```
> Tuple(1,2,3)
[1,2,3]
> Tuple([1,2,3])
[1,2,3]
> Tuple()
[]
```

### `Tuple.duplicate(val, n)`

Returns a Tuple filled with `n` of `val`.

```
> Tuple.duplicate('foo', 3)
['foo', 'foo', 'foo']
```


### `Tuple.fromDate(date)`

Given a Javascript `Date` object, returns tuple of the form `(year, month, date)`.

```
> const aDate = new Date('1986-04-25')
> Tuple.fromDate(aDate)
[1986, 4, 25]
```

### `Tuple.toDate(dateTuple)`

Given a tuple of the form `(year, month, date)`, returns a Javascript `Date` object that matches it.

```
> const aDate = Tuple(1986, 04, 25)
> Tuple.toDate(aDate)
1986-04-25T00:00:00.000Z
```


## Prototype Methods

### `Tuple.prototype.append(val)`

Returns a new Tuple with the specified value appended to the original. Equivalent to `Array.prototype.push`, but returns the tuple.

```
> const t = Tuple(1,2,3)
> t.append(4)
[1, 2, 3, 4]
```

### `Tuple.prototype.deleteAt(index)`

Returns a new Tuple, less the value at the index specified.

```
> const t = Tuple(1,2,3)
> t.deleteAt(2)
[1, 2]
```

### `Tuple.prototype.duplicate(val, n)`

Prototype version of `Tuple.duplicate()`, allowing it to be chained to other Tuple methods. Fills an empty Tuple with `n` of `val`.

```
> const t = Tuple()
> t.duplicate('foo', 3)
['foo', 'foo', 'foo']
```

### `Tuple.prototype.eq(tuple2)`

Checks the tuple against another tuple, returns true if all values are identical and in the same order.

```
> const t = Tuple(1,2,3)
> t.eq(Tuple(1,2,3))
true

> t.eq(Tuple(3,2,1))
false
```

### `Tuple.prototype.insertAt(index, val)`

Returns a new Tuple, with a value added at the index specified.

```
> const t = Tuple(1,2,3)
> t.insertAt(0,0)
[0, 1, 2, 3]
```

### `Tuple.prototype.toArr()`

Returns a proper [fully mutable] Array version of the Tuple.

```
> const t = Tuple(1,2,3)
> t[0] = 0
// Throws a TypeError

> const a = t.toArr()
> a[0] = 0
> a
[0, 2, 3]
```

### `Tuple.prototype.toStr()`

Returns a string representation of the Tuple.

```
> const t = Tuple(1,2,3)
> t.toStr()
'(1,2,3)'
```

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