npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sb-js

v0.3.0

Published

A Node.js library implementing a simple StringBuffer, much like the Java class.

Downloads

50

Readme

sb-js

Purpose

A Node.js library implementing a simple StringBuffer, much like the Java class.

Efficiently uses an Array internally, rather than continually appending Strings.

Examples

Setup

Add sb-js to your project or package.json file:

npm install sb-js

Require sb-js in your code:

StringBuffer = require("sb-js").StringBuffer

Note: this library is now implemented in TypeScript, but these examples are in CoffeeScript. For users of TypeScript, see the declaration file for this library at:

https://github.com/cjoakim/sb-js/blob/master/lib/sb-js.d.ts

StringBuffer

Construct a StringBuffer, optionally provide an initial String value.

Original "snake_case" methods add(), add_line(), newline(), to_string(), as_lines(), and is_empty() are available. Corresponding new "camelCase" methods addLine(), newLine(), toString(), asLines(), and isEmpty() are also available.

sb = new StringBuffer()
sb.is_empty()  -> true
sb.isEmpty()  -> true
sb.to_string() -> ""
sb.toString() -> ""

sb.add("one")
sb.is_empty()  -> false

sb.add(",two")
sb.to_string() -> "one,two"

sb.newline()
sb.add_line("three")
sb.add_line(null)      // null values ignored
sb.addLine(undefined)  // undefined values ignored

sb.to_string() -> "one,two
three
"
sb.as_lines()  -> "["one,two","three",""]"
sb.asLines()  -> "["one,two","three",""]"

sb2 = new StringBuffer("  hello world  ")
sb2.is_empty()  ->  false
sb2.as_lines()  -> "["  hello world  "]"
sb2.to_string() -> "  hello world  "
sb2.to_string(true) -> "hello world"

StringBuffer.VERSION  -> 0.3.0

Test Results

Running "mocha_istanbul:coverage" (mocha_istanbul) task


  StringBuffer
    VERSION number is exposed by the API
      ✓ defines VERSION
    original snake_case API
      ✓ should construct an empty instance with no constructor argument
      ✓ should construct a populated instance with a constructor String argument
      ✓ should implement method 'as_lines'
      ✓ should optionally trim the result of to_string
    new camelCase API
      ✓ should construct an empty instance with no constructor argument
      ✓ should construct a populated instance with a constructor String argument
      ✓ should implement method 'asLines'
      ✓ should optionally trim the result of toString


  9 passing (10ms)

=============================================================================
Writing coverage object [/Users/cjoakim/github/sb-js/coverage/coverage.json]
Writing coverage reports at [/Users/cjoakim/github/sb-js/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 100% ( 46/46 )
Branches     : 92.86% ( 13/14 )
Functions    : 100% ( 14/14 )
Lines        : 100% ( 46/46 )
================================================================================

Release History

  • 2015-05-02 v0.3.0 Renamed the source to sb-js so as to generate file 'lib/sb-js.d.ts'.
  • 2015-04-22 v0.2.0 Implementation language is now TypeScript. API expanded to both snake_case and camelCase.
  • 2015-01-24 v0.1.1  Changed line endings from "\n" to os.EOL. Replaced jasmine with mocha and istanbul.
  • 2014-11-06 v0.1.0  Initial working version; implemented in CoffeeScript.
  • 2014-11-06   v0.0.1  alpha 1