0.0.4-alpha • Published 2 months ago

@qpyracuk/text-builder v0.0.4-alpha

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

@qpyracuk/text-builder

Introduction

Immediately after writing an object serializer in XML @qpyracuk/xml-builder, an idea came to me - based on an already existing “engine”, create an object serializer into plain text. Having brewed 1 more cup of coffee, I got to work, and half an hour later, another bag was ready!

Installation

This is a JS library available through the npm registry. Before installation, you need to download and install Node.js. Requires Node.js v8.0.0 or higher.

If this is a completely new project, be sure to create a package.json file using the npm init command.

To install the package, enter the npm install @qpyracuk/text-builder command in the console.

npm install @qpyracuk/text-builder

Features

  • Support for Map and Set data structures;
  • Pretty output mode;
  • Adjusting tab size in pretty mode;
  • Displaying variable types;
  • High serialization speed;
  • Changing the encoding.

Quick Start

After installing the package, import the library.

For ESMAScript modules:

import TEXT from '@qpyracuk/text-builder';

For CommonJS modules:

const TEXT = require('@qpyracuk/text-builder');

Usage example

We create an object that needs to be traversed

const futureText = {
  primitive: '1',
  object: {
    primitive: 3,
    array: ['1', 2, 'three'],
    set: new Set([1, 2, new Map([['key', { field: { value: 100 } }]])]),
    map: new Map([['key', { value: 10 }]])
  }
};

const builder = TEXT.createBuilder({ pretty: true, typed: true });
const text = builder.stringify(futureText);

Options

pretty: boolean

Generate a text model of an object with indents and tabs.

typed: boolean

Sign the type of fields of objects or variables.

tab: number | 'tab'

Tab size in spaces if specified as a positive numeric value. Is it possible to specify 'tab' and then all whitespace characters will become \t.

Builder methods

stringify(data: any): string

Serializes data into text. Yes, it's simple!

Author

The author of the library is Pobedinskiy David.

Bugs

If you encounter unexpected errors, please let me know. By e-mail qpyracuk@gmail.com or in Telegram.

Support the author

If my work has helped you make your life easier, you can support me with your donations.

Boosty

Patreon

Search npm for other libraries with the @qpyracuk prefix. Perhaps you will find something useful for your project.

0.0.4-alpha

2 months ago

0.0.3-alpha

3 months ago

0.0.2-alpha

3 months ago

0.0.1-alpha

3 months ago