code-trimmer

0.0.6 • Public • Published

code-trimmer

Trim source code into the beauty if needed for node, and autocomplete-me.

code-trimmer will indent a given chunk of source code, started with unnecessarily added whitespaces or tabs, by trimming the tabs and white-spaces in a consistent way, scanning through line by line as following :

NPM Version

const trimmer = require("./code-trimmer")
 
const source = "\t\t\t\t\t\t\t(async () => {\n\t\t\t\t\t\t\t\tconst result = await fire(\n\t\t\t\t\t\t\t\t\t'trimmed!',\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})()"
 
const res = trimmer.trim(source)
 
console.log(res)

origin source =>

/*
        (async () => {
            const result = await Swal.fire(
                'Success',
                'Your code is saved!',
                'success'
            )
 
            if (result) {
                window.location = `${BASE_URL}/main`
            }
        })()
*/

into =>

/* 
(async () => {
    const result = await Swal.fire(
        'Success',
        'Your code is saved!',
        'success'
    )
 
    if (result) {
        window.location = `${BASE_URL}/main`
    }
})()
*/

Installation for Node.js

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm install code-trimmer

Installation for Web Browser

CDN

<script src="https://cdn.jsdelivr.net/npm/code-trimmer@0.0.5/code-trimmer.js"></script>

<script>
const trimmer = require("./code-trimmer")

const source = "\t\t\t\t\t\t\t(async () => {\n\t\t\t\t\t\t\t\tconst result = await fire(\n\t\t\t\t\t\t\t\t\t'trimmed!',\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})()"

const res = trimmer.trim(source)

console.log(res)
</script>

Features

* Do one thing well
* Simple to use

Contributing

Contributing Guide

License

MIT

Package Sidebar

Install

npm i code-trimmer

Weekly Downloads

3

Version

0.0.6

License

MIT

Unpacked Size

7.14 kB

Total Files

6

Last publish

Collaborators

  • boraseoksoon