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

galao

v1.0.5

Published

ActiveSupport-like core class extensions for Javascript/Coffeescript

Downloads

3

Readme

Version Node version Build Status Downloads License

Galao

This Node.js package provides a ActiveSupport-flavoured Javascript core object extensions. A detailed list of features can be found below.

This project is work in progress and will grow in size continually when I feel the need to add certain functions. See "Contributing" if you miss any functionality, I'm always happy to merge your enhancements in!

Usage

Node.JS

Simple require galao in your application and it will be accessible from anywhere in your app:

require 'galao'

Browser

There is a browser version in the lib directory. Download the file from Github or require locally from your node_modules directory.

Caveats: The browser treats numbers differently than Node.JS. A number directly followed by a dot is interpreted as a decimal number without a decimal value and thus results in an exception. To avoid this exception and still use the number functions, bracket the number:

5.minutes()
=> Exception

(5).minutes()
=> All good!

Methods

Array::compact()

Returns a new array without any null or undefined elements.

coffee> [1, 2, 3, null].compact()
[ 1, 2, 3 ]
coffee> [1, 2, 3, undefined].compact()
[ 1, 2, 3 ]

Array::find()

Returns the first element of the array matching the callback condition.

coffee> [{foo:1}, {foo:2}, {foo:3}].find (elem, index, array) -> elem.foo==2
{ foo: 2 }
coffee> [{foo:1}, {foo:2}, {foo:3}].find (elem, index, array) -> elem.foo==20
null

Number::seconds()

Interpret given number as seconds and return value in milliseconds.

coffee> 10.seconds()
10000

This function (and its related functions minutes(), hours(), etc.) becomes very useful for specifying timeouts and intervals:

setTimeout ->
  console.log 'Timeout ended'
, 5.seconds()

There is also a singular version of this method simply for syntactical sugar. Instead of writing 1.minutes(), which is syntactically incorrect, one can also write 1.minute().

Number::minutes()

Interpret given number as minutes and return value in milliseconds.

coffee> 2.minutes()
120000

Number::hours()

Interpret given number as hours and return value in milliseconds.

coffee> 2.hours()
7200000

Number::days()

Interpret given number as days and return value in milliseconds.

coffee> 2.days()
172800000

Number::even()

Checks whether the number is even or not.

coffee> 5.even()
false
coffee> 6.even()
true

Number::odd()

Checks whether the number is odd or not.

coffee> 5.odd()
true
coffee> 6.odd()
false

String::capitalize()

Capitalize first letter in string, remaining letters will stay untouched.

coffee> "test".capitalize()
'Test'
coffee> "tesT".capitalize()
'TesT'

String::startsWith(prefix)

Returns true if the string starts with the given prefix.

coffee> "foo".startsWith 'f'
true
coffee> "foo".startsWith 'b'
false

String::endsWith(prefix)

Returns true if the string ends with the given prefix.

coffee> "foo".endsWith 'o'
true
coffee> "foo".endsWith 'f'
false

String::repeat(n)

Repeats the string n times.

coffee> "foo".repeat 2
'foofoo'

Contributing

Feel free to send me pull requests on Github, contributions are always welcome!