🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

json-multiline-strings

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-multiline-strings

One shortcoming of JSON is the lack of multiline support. This module will split/join multiline strings to string arrays which is more readable.

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
11
-15.38%
Maintainers
1
Weekly downloads
 
Created
Source

json-multiline-strings

One shortcoming of JSON is the lack of multiline support. This module will split/join multiline strings to string arrays which is more readable.

EXAMPLE

Convert to multiline variant:

var input = {
    "foo": "bar",
    "long": "text with\nseveral\nline breaks"
}
console.log(JSON.stringify(jsonMultilineStrings.split(input), null, '    '))
{
    "foo": "bar",
    "long": [
        "text with",
        "several",
        "line breaks"
    ]
}

Convert back to original json:

var input = {
    "foo": "bar",
    "long": [
        "text with",
        "several",
        "line breaks"
    ]
}
console.log(JSON.stringify(jsonMultilineStrings.join(input), null, '    '))
{
    "foo": "bar",
    "long": "text with\nseveral\nline breaks"
}

API

jsonMultilineStrings.split(data, options) resp. jsonMultilineStringsSplit(data, options)

Processes input data recursively and convert all multiline strings to string arrays.

Options:

  • exclude: Exclude the following paths from modifications. Give an array of string arrays, e.g. [ [ 'foo', 'bar' ], [ 'test' ] ]. This would not modify the paths 'foo/bar' and 'test'.

jsonMultilineStrings.join(data, options) resp. jsonMultilineStringsJoin(data, options)

Processes input data recursively and convert all string arrays to multiline strings.

Options:

  • exclude: Exclude the following paths from modifications. Give an array of string arrays, e.g. [ [ 'foo', 'bar' ], [ 'test' ] ]. This would not modify the paths 'foo/bar' and 'test'.

INSTALL

JS usage via npm

npm install --save json-multiline-strings
var jsonMultilineStrings = require('json-multiline-strings')
jsonMultilineStrings.split(...)
jsonMultilineStrings.join(...)

PHP usage via composer

composer install plepe/json-multiline-strings
jsonMultilineStringsSplit(...)
jsonMultilineStringsJoin(...)

Development

git clone https://github.com/plepe/json-multiline-strings.git
cd json-multiline-strings
npm install
composer install

FAQs

Package last updated on 09 Nov 2017

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