0.11.24 • Published 3 days ago

spacetrim v0.11.24

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 days ago

✂️ Space trim

License of ✂️ Space trim NPM Version of ✂️ Space trim Quality of package ✂️ Space trim lint test Known Vulnerabilities Issues Socket

Spacetrim is trimming string from all 4 sides.

It is very helpful to keep pretty code indentation without keeping strange spaces inside a string.

░ is whitespace and spaceTrim will trim the string at the boundaries ╔═╗

░░░░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░╔═════╗░
░░░░░░░║Hello║░░
░░░░░░░║Space║░░░
░░░░░░░║Trim ║░░░░
░░░░░░░╚═════╝░░░░░
░░░░░░░░░░░░░░░░░░░░

Usage

npm i spacetrim
import spaceTrim from 'spacetrim';

const trimmed = spaceTrim(`

    Hello
    Space
    Trim


`);

console.log(trimmed);

/*
Hello
Space
Trim
*/

See more examples in simple tests.

Nesting

This is very usefull when you want to trim multiline strings inside multiline strings.

import { spaceTrim } from 'spacetrim';

const trimmed = spaceTrim(
    (block) => `

        Numbers
            ${block(['1', '2', '3'].join('\n'))}
        Chars
            ${block(['A', 'B', 'C'].join('\n'))}

`,
);

console.log(trimmed);

/*
Numbers
    1
    2
    3
Chars
    A
    B
    C
*/

See more examples in nesting tests.

Asynchronous nesting

You can also trim multiline strings which are fetched asynchronously inside multiline strings.

import { spaceTrim } from 'spacetrim';

const trimmed = await spaceTrim(
    async (block) => `

        TypeScript:
            ${await fetch('https://en.wikipedia.org/wiki/TypeScript').then(
                (result) => result.text(),
            )}


`,
);

console.log(trimmed);

/*
TypeScript:
    TypeScript is a free and open source programming language...
*/

See more examples in asynchronous nesting tests.

🖋️ Contributing

I am open to pull requests, feedback, and suggestions. Or if you like this utility, you can ☕ buy me a coffee or donate via cryptocurrencies.

You can also ⭐ star the spacetrim package, follow me on GitHub or various other social networks.

✨ Partners

           

Become a partner

0.11.24

3 days ago

0.11.23

6 days ago

0.11.22

11 days ago

0.11.21

13 days ago

0.11.20

14 days ago

0.11.19

14 days ago

0.11.16

19 days ago

0.11.17

19 days ago

0.11.18

19 days ago

0.11.15

20 days ago

0.11.11

21 days ago

0.11.12

21 days ago

0.11.13

21 days ago

0.11.14

21 days ago

0.11.10

23 days ago

0.11.9

30 days ago

0.11.8

1 month ago

0.11.7

1 month ago

0.11.6

1 month ago

0.11.5

2 months ago

0.11.3

2 months ago

0.11.4

2 months ago

0.11.2

2 months ago

0.11.1

2 months ago

0.11.0

2 months ago

0.10.0

2 months ago

0.9.27

3 months ago

0.9.26

3 months ago

0.9.25

3 months ago

0.9.24

3 months ago

0.9.23

3 months ago

0.9.21

3 months ago

0.9.22

3 months ago

0.9.20

3 months ago

0.9.18

4 months ago

0.9.19

4 months ago

0.9.16

4 months ago

0.9.17

4 months ago

0.9.15

4 months ago

0.9.14

4 months ago

0.9.13

4 months ago

0.9.12

4 months ago

0.9.11

4 months ago

0.9.9

4 months ago

0.9.10

4 months ago

0.9.8

4 months ago

0.9.7

4 months ago

0.9.6

4 months ago

0.9.4

5 months ago

0.9.3

5 months ago

0.9.5

5 months ago

0.9.2

7 months ago

0.9.1

7 months ago

0.9.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.6.2

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.1.4

2 years ago

0.4.3

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.2

2 years ago

0.1.0

3 years ago