1.8.1 • Published 3 years ago

object-to-text v1.8.1

Weekly downloads
89
License
MIT
Repository
github
Last release
3 years ago

object-to-text

Recursive nested text replacer that converts any data objects into strings using templates.

Examples

very simple example

const { toText } = requrie('object-to-text')

let data = { someProperty: "World" }
let text = toText(data, "Hello {someProperty}")
// text === "Hello World"

simple example

const { toText } = requrie('object-to-text')

let data = { someProperty: "World", cities: ["London", "New York", "Paris", "Moscow", "Tokyo"] }
let text = toText(data, "Hello {someProperty}!\nHere's a list of some must-see cities: {cities:\n - {$}}")

/* text === "Hello World!
Here's a list of some must-see citites:
 - London
 - New York
 - Paris
 - Moscow
 - Tokyo"
*/

a bit better variant of that example:

const { toText } = requrie('object-to-text')

let data = {

    someProperty: "World",
    cities: [
        {name: "London",    code: "LND" },
        {name: "New York",  code: "NYC" },
        {name: "Paris",     code: "PRS" },
        {name: "Moscow",    code: "MSC" },
        {name: "Tokyo",     code: "TKY" }
    ]
}

let text = toText(data, "Hello {someProperty}!\nHere's a list of some must-see cities: {cities:\n - {name}}")

/* text === "Hello World!
Here's a list of some must-see citites:
 - London
 - New York
 - Paris
 - Moscow
 - Tokyo"
*/
1.8.1

3 years ago

1.8.0

3 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.3.2

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago