abcnews / alternating-case-to-object

Convert an alternating cased string to a JSON object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement objectToAlternatingCase function

phocks opened this issue · comments

In response to Ash's question, it might be an idea to quickly implement this functionality.

So we can do somthing like:

import { objectToAlternatingCase } from "@abcnews/alternating-case-to-object";

const myObject = { test: "object" };

const myString: string = objectToAlternatingCase(myObject);

@AshKyd has said he's rolled his own version of this, so it could be a simple matter of pasting it in this repo with a little export.

I'm using this. It doesn't deal with complex data types or anything.

function actoEncode(obj) {
  return Object.entries(obj)
    .map(([key, value]) => {
      return [key.toUpperCase(), String(value).toLowerCase()].join('');
    })
    .join('');
}

I don't think it needs to deal with much. Strings, Numbers, Booleans ... anything else?

The decoder also handles arrays so probably also that.

The decoder also handles arrays so probably also that.

Yep, good point. So group: ['first', 'second', 'third'] will turn into 'GROUPfirstGROUPsecondGROUPthird'