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

@marxlnfcs/dotize

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@marxlnfcs/dotize

A Typescript library to convert complex objects/arrays to dotized key-value object

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
Maintainers
1
Weekly downloads
 
Created
Source

Dotize

A simple TypeScript library to convert complex objects into simple key value pairs

NPM Version Package License NPM Downloads Package Size

Installation

npm i @marxlnfcs/dotize

Usage

import { Dotize, dotify, parse } from '@marxlnfcs/dotize';

// source object
const obj: any = {
    "key1": 'value1',
    "key2": [
        {
            "foo": "bar"
        },
        "weird_item_inside_an_array_of_objects"
    ],
    "key3": {
        "foo": "bar",
    }
};

// dotify source object
const dotified = Dotize.dotify({ ... });
const dotified = dotify({ ... });

/**
 * Output:
 * {
 *  "key1": "value",
 *  "key2.[0].foo": "bar",
 *  "key2.[1]: "weird_item_inside_an_array_of_objects",
 *  "key3.foo": "bar",
 * }
 */

// parse dotified object
const parsed = Dotize.parse({ ... });
const parsed = parse({ ... });

Options

Dotize.dotify( ... ):

/**
 * The prefix will be added to every key on depth 0
 * @example "$"
 * @default null
 */
prefix: string;

/**
 * Defines the separator that will be used to create the path
 * @example "_"
 * @default "."
 */
separator: string;

/**
 * The array mode defines how arrays are handled
 * > dotify: The index will be set as plain number. Example: foo.0.bar
 * > dotify-bracket: The index will be surrounded with brackets (default). Example: "foo.[0].bar"
 * > dotify-curly-bracket: The index will be surrounded with curly brackets. Example: "foo.{0}.bar"
 * > keep: Arrays will be ignored. Example: { "foo": [ { "bar": "Hello World!" } ] }
 */
arrayMode: 'dotify'|'dotify-bracked'|'dotify-curly-bracket'|'keep';

/**
 * The method processes an object to the defined maxDepth. All beyond the maxDepth gets added to the dotified object as a whole
 */
maxDepth: number;

Dotize.parse( ... ):

/**
 * The prefix will be removed from every key in the dotified object
 * @example "$"
 * @default null
 */
prefix: string;

/**
 * Defines the separator that has been used to dotify the object
 * @example "_"
 * @default "."
 */
separator: string;

/**
 * The array mode defines how arrays are handled
 * > dotify: The index is set as plain number. Example: foo.0.bar
 * > dotify-bracket: The index is surrounded with brackets (default). Example: "foo.[0].bar"
 * > dotify-curly-bracket: The index is surrounded with curly brackets. Example: "foo.{0}.bar"
 */
arrayMode: 'dotify'|'dotify-bracked'|'dotify-curly-bracket';

FAQs

Package last updated on 08 Aug 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