# @abcnews/alternating-case-to-object

> Convert an alternating case string to a JSON object

Latest version **3.2.0** (published 2025-05-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install @abcnews/alternating-case-to-object
pnpm add @abcnews/alternating-case-to-object
yarn add @abcnews/alternating-case-to-object
bun add @abcnews/alternating-case-to-object
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2025-05-05 |
| First published | 2018-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 1 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | drzax, andrewkesper, phocks, jtfell, ashkyd |
| Keywords | string, object, case |

## Links

- npm: https://www.npmjs.com/package/@abcnews/alternating-case-to-object
- Repository: https://github.com/abcnews/alternating-case-to-object
- Homepage: https://github.com/abcnews/alternating-case-to-object#readme
- Issues: https://github.com/abcnews/alternating-case-to-object/issues
- npm.io page: https://npm.io/package/@abcnews/alternating-case-to-object

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 3.2.0 (latest) — 2025-05-05
- 3.1.1 — 2023-07-17
- 3.1.0 — 2022-11-24
- 3.0.2 — 2021-05-03
- 3.0.1 — 2021-02-23
- 3.0.0 — 2021-02-23
- 2.0.1 — 2020-06-05
- 2.0.0 — 2018-02-21

## README

# Alternating Case to Object

A function to convert alternating case (`"ALTERNATINGcase"`) strings to objects
(`{alternating: 'case'}`) and vice versa.

The ACTO string format supports numbers, bools, nulls, and lowercase
strings (a-z0-9), as standalone values or as arrays.

This library provides a `parse` and `stringify` method to convert objects from
and to strings respectively.

## Usage

1. Install with `npm i @abcnews/alternating-case-to-object`
2. Import the library with `import {parse, stringify} from '@abcnews/alternating-case-to-object'`

### Convert an object to a string

```js
stringify({
  prop: 'value',
  second: 'thing',
  allowed: true,
  things: [100, 101],
});

// "PROPvalueSECONDthingALLOWEDyesTHINGS100THINGS101"
```

### Options

#### propMap:Object

Props in the config will be renamed if they occur in this object. Note the
propMap is the same format as you pass to `parse()`, so the map is applied in
the opposite direction.

```javascript
stringify(
  {
    'kebab-case': 'value',
  },
  {
    propMap: {
      kebabcase: 'kebab-case',
    },
  }
);

// "KEBABCASEvalue"
```

### Parse a string to an object

```javascript

parse('PROPvalueSECONDthingALLOWEDyesTHINGS100');

// >>>

{
  prop: 'value',
  second: 'thing',
  allowed: true,
  things: 100
}
```

#### Automatic type inference

- Number values will be parsed as floats.
- The values `"true"`, `"yes"`, `"false"` & `"no"` will be converted to the booleans `true`, `true`, `false` & `false`, respectively.
- If a prop appears more than once, multiple values will be returned as an array:

```javascript
parse('GROUPfirstGROUPsecondGROUPthird');

// >>>

{
  group: ['first', 'second', 'third'];
}
```

Every value in a prop which appears multiple times must be of the same type or an exception will be thrown. For example, this will throw:

```javascript
parse('AtrueAstr');
```

### Options

#### arrayProps:Array

Props in this array will always be returned as arrays, even if they occur in the config string zero or one time.

```javascript
parse('AtrueAfalseBvalueAtrueDvalue', {
  arrayProps: ['a', 'b', 'c']
});

// >>>

{
  a: [true, false, true],
  b: ['value'],
  c: [],
  d: 'value'
}
```

#### propMap:Object

Props in the config will be renamed if they occur in this object.

```javascript
parse('CAMELCASEtrueKEBABCASE100', {
  propMap: {
    camelcase: 'camelCase',
    kebabcase: 'kebab-case'
  }
});

// >>>

{
  camelCase: true,
  'kebab-case': 100
}
```

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