Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@abcnews/alternating-case-to-object

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@abcnews/alternating-case-to-object

Convert an alternating case string to a JSON object

  • 3.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

Alternating Case to Object

A function to convert ALTERNATINGcase strings to objects.

Usage

npm i @abcnews/alternating-case-to-object
const alternatingCaseToObject = require('@abcnews/alternating-case-to-object');

alternatingCaseToObject('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:
alternatingCaseToObject('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:

alternatingCaseToObject('AtrueAstr');

Options

You can pass an object as a second argument, defining one or more 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.

alternatingCaseToObject('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.

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

// >>>

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

Keywords

FAQs

Package last updated on 17 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc