Skip to content

Spacetrim is trimming string from all 4 sides. It is very helpful to keep pretty code indentation without keeping a strange spaces inside a strings.

License

Notifications You must be signed in to change notification settings

hejny/spacetrim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f7b37b4 · Jan 2, 2025
Dec 31, 2021
Jan 25, 2024
Mar 23, 2023
Feb 26, 2024
Sep 27, 2022
Feb 26, 2024
Nov 9, 2021
Feb 2, 2022
Oct 31, 2024
Apr 24, 2024
Nov 13, 2021
Oct 20, 2021
Sep 23, 2024
Sep 23, 2024
Nov 9, 2021
Oct 31, 2024
Oct 31, 2024
Sep 27, 2022
Nov 15, 2021
Sep 27, 2022

Repository files navigation

✂️ 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

Collboard       WebGPT       Promptbook

Become a partner