Giter Site home page Giter Site logo

humanize's People

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  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

humanize's Issues

document bug fix versions

In light of #27 and friends, we should add a CHANGES.md or similar to make it easy for people to find out when certain changes were made or issues were resolved.

@hijonathan @b-ash What do you guys think?

Please include a version inside the code

I think it would be helpful to have a comment on the top saying which version is it, since I just copy/paste the RAW text from github every time I update my copy, and it's not easy to know what version of the code I already have. it's pretty common anyway.. Thanks!

Humanize.truncateWords returns null when input has less number of words

Humanize.truncateWords("hello world", 2)
null
Humanize.truncateWords("hello world", 1)
"hello ..."

The primary reason one wants to use methods such as truncateWords is if the size increases beyond certain point, truncate it (and leave it untouched if input is smaller in length). Currently the method is returning null if input has less no. of words than requested.

TypeScript definitions

I've started working with humanize as part of a TypeScript application, and ended up just going ahead and creating definitions for all the exposed methods. Is this something you'd be willing to include directly in the repository and npm package? If so I'm happy to submit a PR with the changes. If not I can create and maintain a separate typings repository to host the definitions, but it's a much better user experience to have it directly in the package.

Let me know! ๐Ÿ˜„

times doesn't support thrice

Right now, Humanize.times overrides have ' times' appended to them, which is sometimes desirable, but not always.

coffee> Humanize.times 3, {3:'thrice'}
'thrice times'

I think the above should return thrice, but I can imagine other circumstances like:

coffee> Humanize.times 12, {12:'douze'}
'douze times'

where we might want to append 'times'.

titleCase unusable when required using destructured assignment

Input

{titleCase} = require 'humanize-plus'
titleCase('test')

Output

TypeError: Object object has no method 'capitalize'
    at doTitleCase (/Users/kevin/repos/test/node_modules/humanize-plus/public/src/humanize.js:414:71)
    at Humanize.titlecase.Humanize.titleCase (/Users/kevin/repos/test/node_modules/humanize-plus/public/src/humanize.js:427:12)

npm package is pulling in development files

When I run the install command:

npm install --save humanize-plus

npm installs EVERYTHING in this repository, including the src, bin and __tests__ directories, along with other files which are only needed in development.

image

Telling npm what to include should lighten the load:

In package.json:

"files": [
    "dist/humanize.js"
  ],
  "main" : "dist/humanize.js",

Thanks for a useful module!

Rewrite functions as ES6 modules

So we can now require each function separately without having to include the whole library, this will be helpful to anyone trying to optimize their bundle on the client side, and will make it possible in the future to use tree shaking (i.e. removing unused code) when Node and Webpack supports ES6 modules.

๐Ÿ™‡

Humanize.times is broken for node

times references window.isFinite via the local isFinite helper. window is undefined in node. There were previously no tests for the times method, but even if there had been, the jasmine test runner creates a mock window object which would have masked the problem.

Should check for 'undefined' or `null` parameter values

All methods should check validity of parameters.

For example, https://github.com/HubSpot/humanize/blob/master/src/humanize.js#L281

truncate(str, length = 100, ending = '...')
{
   if (str && str.length > length) ...
}

This is useful when calling Humanize.truncate directly from data received from db queries and other external entities. Validating parameters outside (before calling the methods of Humanize) is code redundancy and can be avoided if the library takes care of it.

Please change picture example to be more neutral

Could we please change the picture example in the README? This currently reads:

// "Asians took pictures of food 3 times"

This is a great library I have started to integrate into my company. When it comes to the documentation that people will be reading it would be nice to have neutral examples that don't potentially call on stereotypes - especially if there are similar examples that suffice.

Happy to make a pull request for you.

"toFixed" - why does it exists?

excuse me but I want to understand why did you make your own "toFixed" method when there's one already exist natively in all browsers? how does it defer?

Thank you

standardize on camelCased method names

Re: #23 I think we should move toward a standard naming convention for Humanize public methods.

I like camelCase for v2, and I think we should make camelCase names in the 1.x branch as well. Existing non-camelCase names can ( and should? ) just be aliases for the names that will stick around in v2.

Sound reasonable?

Don't store js in repo

Makes pull requests weird, and it's hard to trust that what's in the minified versions is actually the compiled change. It could be bad stuff...

Put the js in the release and published versions, but not in the repo itself.

v2.0.0-alpha

Let's use this issue to create a roadmap for humanize v2.

Some things we may want to do:

  • Remove methods that were deprecated in 1.x
  • Drop support for node 0.6.x #13 dd4d5ca
  • Move to grunt ~0.4.1 #13 dd4d5ca
  • intword has been removed from the v2.0.0alpha branch in favor of compactInteger.
  • Naming conventions are addressed in #26
  • truncatenumber is renamed boundedNumber in 98a5be8
  • Consider removing intComma as well. I don't think it adds value over formatNumber.
  • Consider removing public/ from git as it's really just compiled output, not source code.

filesize unit should be capitalized B

In the readme and the code I see that filesize returns Gb, Mb, and Kb and bytes as values. Even ignoring the 1024/1000 thing those should still be GB, MB, kB, and bytes. With a capital B (for byte) instead of a lowercase b (for bit), and also kilo is not uppercased when used as 1000.

Reference: http://en.wikipedia.org/wiki/Byte#Unit_symbol

(Awesome library by the way)

TIME_FORMATS oject keys

I don't find it elegant when TIME_FORMATS are written:

var TIME_FORMATS = [{
        name: 'second',
        value: 1e3
    }, {
        name: 'minute',
        value: 6e4
    }
}];

Instead of:

var TIME_FORMATS = {
    second : 1e3,
    minute: 6e4
};

Especially when the line after that is where LABELS_FOR_POWERS_OF_KILO is configured like how things should be configured. it's an odd choice when both dictionaries should serve the same purpose.

crashes in React Native

I pulled this module into a React Native project using

npm install --save humanize-plus

and all I did to start using it was:

var humanize = require('humanize-plus');
humanize.formatNumber(123456);

and I got the following error:

TransformError: /Users/michael/gitprojects/test/node_modules/humanize-plus/dist/humanize.js:
Couldn't find preset "es2015-riot" relative to directory "/Users/michael/gitprojects/test/node_modules/humanize-plus"

I think this might be related to Issue #86, because React Native goes through a transpile step, so it might be finding your unnecessary .babelrc file inside the package files that has es2015-riot defined as a preset:

{
  "presets": ["es2015-riot"]
}

I don't think it matters for this issue, but just in case, here are my versions of React Native:

react-native-cli: 2.0.1
react-native: 0.39.2

method chaining

chaining support would be nice

right now, we have to wrap everything

> Humanize = require("humanize-plus")
> Humanize.truncate(Humanize.titleCase("In 1998 they had this promotion for the Disney film Mulan, where they created a new sauce for the McNuggets called Szechuan sauce"), 14, "...etc")
'In 1998 ...etc'

compared to

> Humanize.titleCase("In 1998 they had this promotion for the Disney film Mulan, where they created a new sauce for the McNuggets called Szechuan sauce").truncate(14, "...etc")

Extra comma when Humanizing a list of strings

Hi,

When I use Humanize on a list of strings, I get an extra comma before the and.

Some code that works in Linqpad:

var list = new List<string>() {"Text1", "Text2", "Text3", "Text4"};
list.Humanize().Dump();

Here is the output (note the extra comma):

Text1, Text2, Text3, and Text4

Cheers,

Mike

P.S Just noticed the documentation it is Oxford standard. Is there a separate function call to not do this?

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.