Code Monkey home page Code Monkey logo

string-builder's Introduction

StringBuilder

Known Vulnerabilities

FOSSA Status

NPM

An string builder for Node.js

Installation

npm install string-builder

Usage

const StringBuilder = require("string-builder");
const sb = new StringBuilder();

const buffer = Buffer.from([0x30, 0x31, 0x32]); // 012

sb.append("normal text");
sb.appendLine();
sb.appendFormat("formatted text {0}, {1}", "format 1", "format 2");
sb.appendLine()
sb.append(12)
sb.appendLine()
sb.append(1)
sb.appendLine()
sb.append(0)
sb.appendLine()
sb.appendFormat("formatted text {0}, {1}", 3.6745674, 12);
sb.appendLine()
sb.appendLine(true)
sb.appendLine(false)
sb.appendLine(buffer)
sb.appendLine()
sb.append(undefined);
sb.appendLine()
sb.append(null);
sb.appendLine()
sb.appendFormat("formatted text {0}, {1}", 3.6745674, 1);

console.log("======")
console.log(sb.toString());
console.log("======")

/*
console =>
======
normal text
formatted text format 1, format 2
12
1
0
formatted text 3.6745674, 12

true
false
012


formatted text 3.6745674, 1
======
*/

License

The MIT License (MIT)

Copyright © 2014 Halil İbrahim ŞAFAK

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FOSSA Status

string-builder's People

Contributors

bitdeli-chef avatar christopheredjohnson avatar fossabot avatar gantrim avatar gitter-badger avatar halil avatar ml054 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

string-builder's Issues

NPM release of string builder 0.1.5 appears to have included a .git file in the module.

We are seeing errors similar to this in automated builds:

16:52:50 npm ERR! path [path omitted]/node_modules/string-builder
16:52:50 npm ERR! code EISGIT
16:52:50 npm ERR! git [path omitted]/node_modules/string-builder: Appears to be a git repo or submodule.
16:52:50 npm ERR! git [path omitted]/node_modules/string-builder
16:52:50 npm ERR! git Refusing to remove it. Update manually,
16:52:50 npm ERR! git or move it out of the way first.
16:52:50 
16:52:50 npm ERR! A complete log of this run can be found in:
16:52:50 npm ERR!     [path omitted]

This was during an npm install command, and it was working on string-builder 0.1.5, though the workspace may have had a previous version before this.

Invalid handling of numbers / falsy

    it("a", () => {
        const sb1 = new StringBuilder("init");
        sb1.append(0);

        const sb2 = new StringBuilder("init");
        sb2.append(1);

        console.log(sb1.toString());
        console.log(sb2.toString());

        const sb_true = new StringBuilder("init");
        sb_true.append(true);

        const sb_false = new StringBuilder("init");
        sb_false.append(false);

        console.log(sb_true.toString());
        console.log(sb_false.toString());
    })

output:

init
init1
inittrue
init

so if pass falsy nothing is appended to output which is really misleading.

Bug in Linux OS

I think there is a bug in this function

StringBuilder.prototype.appendLine = function (v) {
  this.s.push("\r\n");
  if (v) {
    this.s.push(v);
  }
  return this;
};

\r\n will work in Windows OS, while in Linux this will cause problems (by adding '\r')

Version 0.1.7 has breaking changes

Hi,

Sometime ago I reported #13

After your fix some of this features stopped working since currently string-builder only accepts string and numbers. We passed booleans and even buffer and it worked fine. I'm affraid it could break dependent projects.

Let's assume testing code:

var StringBuilder = require("../src/StringBuilder");
var sb = new StringBuilder();

sb.append("normal text ");

sb.appendLine();

sb.appendFormat("formatted text {0},{1}", "format 1", "format 2");

var buffer = Buffer.from([0x30, 0x31, 0x32]);

sb.appendLine()
sb.append(12)
sb.appendLine()
sb.append(1)
sb.appendLine()
sb.append(0)
sb.appendLine()
sb.appendFormat("formatted text {0},{1}", 3.6745674, 12);
sb.appendLine()
sb.appendLine(true)
sb.appendLine(false)
sb.append(buffer)
sb.appendLine()
sb.append(undefined);
sb.appendLine()
sb.append(null);
sb.appendLine()

sb.appendFormat("formatted text {0},{1}", 3.6745674, 1);

console.log("======")
console.log(sb.toString());
console.log("======")

output on 0.1.6:

======
normal text
formatted text format 1,format 2
12
1

formatted text 3.6745674,12

true
012


formatted text 3.6745674,1
======

output on 0.1.7:

======
normal text
formatted text format 1,format 2
12
1
0
formatted text 3.6745674,12





formatted text 3.6745674,1
======

as you can see most of lines are empty in 0.1.7.

Output with my fix:

======
normal text
formatted text format 1,format 2
12
1
0
formatted text 3.6745674,12

true
false012


formatted text 3.6745674,1
======

so it doesn't output anything when value is null or undefined. I will create PR soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.