# @shaenx/js-plus

> utils for javascript

Latest version **1.1.1** (published 2019-08-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install @shaenx/js-plus
pnpm add @shaenx/js-plus
yarn add @shaenx/js-plus
bun add @shaenx/js-plus
```

## 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.1.1 |
| Published | 2019-08-04 |
| First published | 2019-08-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shaenx |
| Maintainers | shaenx |
| Keywords | test |

## Links

- npm: https://www.npmjs.com/package/@shaenx/js-plus
- Repository: https://github.com/Sshahar/js-plus
- Homepage: https://github.com/Sshahar/js-plus#readme
- Issues: https://github.com/Sshahar/js-plus/issues
- npm.io page: https://npm.io/package/@shaenx/js-plus

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2019-08-04
- 1.1.0 — 2019-08-04
- 1.0.0 — 2019-08-01
- 0.0.3 — 2019-08-01
- 0.0.2 — 2019-08-01
- 0.0.1 — 2019-08-01

## README

# js-plus

## Pack Examples

### Basic usage
```
  let subObject = 'Spam'
    let o = { 'SpamA': 1, 'SpamB': 2, 'anonAbc prefixB': 0 }
    let newObject = pack({
        object: o,
        filterFn: (k) => k.startsWith(subObject),
        subobjectName: subObject
    })
```
> Output: { 'anonAbc prefixB': 0, Spam: { SpamA: 1, SpamB: 2 } }

### Using the renameKeyFn param
```
  let subObject = 'Spam'
    let o = { 'SpamA': 1, 'SpamB': 2, 'anonAbc prefixB': 0 }
    let newObject = pack({
        object: o,
        filterFn: (k) => k.startsWith(subObject),
        subobjectName: subObject,
        renameKeyFn: renameKeyWrapper(removePrefix, { prefix: subObject })
    })
```
> Output: { 'anonAbc prefixB': 0, Spam: { A: 1, B: 2 } }

## Example of iteration over array
```
import { pack } from "@shaenx/js-plus/pack"

const SUBOBJECTS = ['Pizza', 'Post', 'Book', 'Phone']
const OBJECT_ARRAY = [
    {
        "Number": "406",
        "Name": "Shaul Raggaza",
        "PizzaNumber": 10,
        "PizzaPublisher": "George Orwell",
        "PizzaUpdateDate": "2019-03-13T00:00:00.000Z",
        "PizzaVersion": 3,
        "PostNumber": null,
        "PostPublisher": null,
        "PostUpdateDate": null,
        "PostVersion": null,
        "BookNumber": null,
        "BookPublisher": null,
        "BookUpdateDate": null,
        "BookVersion": null,
        "PhoneNumber": null,
        "PhonePublisher": null,
        "PhoneUpdateDate": null,
        "PhoneVersion": null
    },
    {
        "Number": "777",
        "Name": "Jornal Dejavu",
        "PizzaNumber": null,
        "PizzaPublisher": null,
        "PizzaUpdateDate": null,
        "PizzaVersion": null,
        "PostNumber": null,
        "PostPublisher": null,
        "PostUpdateDate": null,
        "PostVersion": null,
        "BookNumber": 5555,
        "BookPublisher": "Lily Allen",
        "BookUpdateDate": "2018-02-02T00:00:00.000Z",
        "BookVersion": 2,
        "PhoneNumber": 3333,
        "PhonePublisher": "Joranj",
        "PhoneUpdateDate": "1111-01-01T00:00:00.000Z",
        "PhoneVersion": 6
    },
    {
        "Number": "777",
        "Name": "Bruce list",
        "PizzaNumber": null,
        "PizzaPublisher": null,
        "PizzaUpdateDate": null,
        "PizzaVersion": null,
        "PostNumber": null,
        "PostPublisher": null,
        "PostUpdateDate": null,
        "PostVersion": null,
        "BookNumber": null,
        "BookPublisher": null,
        "BookUpdateDate": null,
        "BookVersion": null,
        "PhoneNumber": null,
        "PhonePublisher": null,
        "PhoneUpdateDate": null,
        "PhoneVersion": null
    }
]

packPersonaPossesions = (object_array, prefixes) => {
    if (!Array.isArray(object_array)) return

    const packMultiplePrefixes = ({ object, prefixes }) => {
        let packedObject = { ...object }
        prefixes.forEach(prefix => packedObject = pack({
            object: packedObject,
            filterFn: (k) => k.startsWith(prefix),
            subobjectName: prefix,
            renameKeyFn: (k) => k.split(prefix)[1]
        }))

        return packedObject
    }

    let parsedAppendixes = []
    object_array.forEach(object => parsedAppendixes.push(packMultiplePrefixes({ object: object, prefixes })))

    return parsedAppendixes
}

let parsedObject = packPersonaPossesions(OBJECT_ARRAY, SUBOBJECTS)
console.log(parsedObject)
```
> Output: [ { Number: '406',
    Name: 'Shaul Raggaza',
    Pizza:
     { Number: 10,
       Publisher: 'George Orwell',
       UpdateDate: '2019-03-13T00:00:00.000Z',
       Version: 3 },
    Post:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Book:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Phone:
     { Number: null, Publisher: null, UpdateDate: null, Version: null } },
  { Number: '777',
    Name: 'Jornal Dejavu',
    Pizza:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Post:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Book:
     { Number: 5555,
       Publisher: 'Lily Allen',
       UpdateDate: '2018-02-02T00:00:00.000Z',
       Version: 2 },
    Phone:
     { Number: 3333,
       Publisher: 'Joranj',
       UpdateDate: '1111-01-01T00:00:00.000Z',
       Version: 6 } },
  { Number: '777',
    Name: 'Bruce list',
    Pizza:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Post:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Book:
     { Number: null, Publisher: null, UpdateDate: null, Version: null },
    Phone:
     { Number: null, Publisher: null, UpdateDate: null, Version: null } } ]

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