Giter Club home page Giter Club logo

useful's Introduction

Useful Functions

This is a node.js module to provide useful miscellaneous functions. For example, min(), max(), and cmp() . Almost all these function are trivially short.

API

exit(d)

Calls process.exit(d) on nextTick. Useful when you print something out then immediately call process.exit(), because sometimes the program exits before the message was printed to stdout.

repeatstr(str, n)

Returns a string which is str repeated n times. Basically, it is the x operator from Perl.

rand(d, n)

Returns a random number [n,n+d). If it is called rand(d), then n=0.

psuedo_foor(d)

There is a problem with some Math functions. For example,

Math.log(1000)/Math.LN10 //=> 2.9999999999999996 oops!

Hence, Math.floor(Math.log(1000)/Math.LN10) returns 2 which is wrong. pseudo_floor(d) returns d if d is within Math.pow(2,-43) of d. 2^-43 was chosen cuz it works on my log10() function for the whole span of the double float number range.

log10(d)

Return log base 10 of d.

order10(d)

Return the base 10 order of magnitude of d.

min(a,b)

Returns the smaller value of a or b.

max(a,b)

Returns the larger value of a or b.

cmp(a,b)

Returns 1 if a > b, - if a < b, and 0 if a === b.

bconcat(bufs)

Returns a new Buffer which is the concatenation of bufs, where bufs is an array of Buffer objects.

isInt(d)

Returns true if d is an integer number, and false otherwise.

isString(s)

Returns true if s is a string, and false otherwise.

isNumber(d)

Returns true if d is a Number, and false otherwise.

isFunction(d)

Returns true if d is a Function, and false otherwise.

useful's People

Contributors

lleo avatar

Watchers

 avatar James Cloos avatar

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.