Giter VIP home page Giter VIP logo

humanize's Introduction

humanize

Javascript data formatter for human readability.

Idea, name, and initial code blatently stolen from milanvrekic/JS-humanize

Can be loaded via AMD or in node directly.

Installation

npm install humanize

Usage:

var humanize = require('humanize');
humanize.date('Y-m-d'); // 'yyyy-mm-dd'
humanize.filesize(1234567890); // '1.15 Gb'

Functions available:

####humanize.noConflict()#### Give control of the "humanize" variable back to its previous owner. Returns a reference to the humanize object.

####humanize.time()#### Retrieves the current time in seconds

####humanize.date(format [, timestamp / JS Date Object = new Date()])#### This is a port of php.js date and behaves exactly like PHP's date

####humanize.numberFormat(number [, decimals = 2, decPoint = '.', thousandsSep = ','])#### Format a number to have decimal significant decimal places, using decPoint as the decimal separator, and thousandsSep as thousands separater

####humanize.naturalDay(timestamp [, format = 'Y-m-d'])#### Returns 'today', 'tomorrow' or 'yesterday', as appropriate, otherwise format the date using the passed format with humanize.date()

####humanize.relativeTime(timestamp)#### Returns a relative time to the current time, seconds as the most granular up to years to the least granular.

####humanize.ordinal(integer)#### Converts a number into its ordinal representation.

####humanize.filesize(filesize [, kilo = 1024, decimals = 2, decPoint = '.', thousandsSep = ',']) #### Converts a byte count to a human readable value using kilo as the basis, and numberFormat formatting

####humanize.linebreaks(string)#### Converts a string's newlines into properly formatted html ie. one new line -> br, two new lines -> p, entire thing wrapped in p

####humanize.nl2br(string)#### Converts a string's newlines into br's

####humanize.truncatechars(string, length)#### Truncates a string to length-1 and appends '…'. If string is shorter than length, then no-op

####humanize.truncatewords(string, numWords)#### Truncates a string to only include the first numWords words and appends '…'. If string has fewer words than numWords, then no-op

humanize's People

Contributors

bfontaine avatar chetan51 avatar joebain avatar michaek avatar p-j avatar pushrax avatar taijinlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

humanize's Issues

[Feature Request] modular exports

It would be really nice to have the ability to just pull in the methods you need, instead of pulling in the entire library for a single method. I have a situation where I only need the numberFormat section, which is 10 lines of code, but to get at it, I need to pull in the entire library, adding unnecessary bloat. These days, when building mobile apps, every byte counts.

As suggested in issue #19, it would be really cool to have the abilty to choose the individual method you want via the destructing syntax:

import { date } from 'humanize';

or you can go the same route as lodash, with individual module exports, so that you can require them in by name:

import date from 'humanize/date';

Add a tag for 0.0.8

It seems like we should have a 0.0.8 tag, since the version has been bumped.

write an abstraction of relativeTime

Right now I return actual strings. instead, I should pass back keys so anybody can use it the way they'd like (and helps with internationalization when needed)

Fix natural time

the calculation is done properly, but still very brittle. Make this more robust. Reference RoR's relative time to now to do it properly

MSF: Support min significant figures instead of decimal places?

Imagine I have 2 disks, one 1TB and one 4TB, both 81% full.

With 0DP, the first will be represented with 5 characters, with decent precision :810GB
but the 4TB HDD used space would be represented with 3: 3TB which is not accurate enough (only 4 possible levels). I could add 1 or 2 decimal places, but then that would make the former unnecessarily long: 810.00GB. This isn't good for typography and space usage.

I think the solution would be min-significant-figures (MSF): the former would get 810GB and the latter, 43.24GB with a value of 2.

Do you agree?

Thanks for the library.

Is there a way to only include the date method?

I am using this module client side and don't want to ship the entire humanize package. Is there a way to require just the date method? Something like this:

import { date } from "humanize";

Just curious!

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.