hubspot / humanize Goto Github PK
View Code? Open in Web Editor NEWA simple utility library for making the web more humane. #hubspot-open-source
License: MIT License
A simple utility library for making the web more humane. #hubspot-open-source
License: MIT License
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?
it should convert "ultra-book By iTunes" to "Ultra-Book by iTunes"
This will lead to errors when the user of this library happen to not use the presets required in the build phase of this library.
Shouldn't you use the prototype object to improve performance?
e.g.:
Humanize.prototype.functionName ...
Whilst trying to use the library in Firefox I am seeing the following error:
missing = in const declaration
Looks like it caused by the following:
const a; now throws a SyntaxError ("missing = in const declaration"): An initializer is required.
ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
Problem line is on 141 and is:
for (const label in LABELS_FOR_POWERS_OF_KILO) {
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("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.
Please see amcharts/amcharts3#29 for details.
It looks like by overwriting standard JS functions, humanize-plus breaks other libraries.
Humanize.times(2, {2: 'twump'})
should return twump
, but instead:
> Humanize.times(2, {2:'twump'})
true
Humanize.compactInteger(-2e-16)
log
is included.Exception is thrown when the package is minified.
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! ๐
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} = require 'humanize-plus'
titleCase('test')
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)
Humanize.compactInteger(-44604);
Current result: "-44k"
Expected result: "-45k"
No?
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.
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!
humanize.filesize(1)
"1 bytes"
I would have expected a value of 1 byte instead.
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.
๐
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.
> Humanize.intword(100, 2)
'NaNundefined'
My expectation was to see 0.1k
Using 1.1.0
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.
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.
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
The link to the minified version of the readme page points to https://raw.github.com/HubSpot/humanize/master/public/src/humanize.min.js, but the link should be (I believe) https://github.com/HubSpot/humanize/raw/master/public/dist/humanize.min.js
Humanize.compactInteger(123456789, 1)
// "123.5M" is great
Humanize.compactInteger(123, 1)
// "123.0" is not good
This should show "123" only
Has this library been deployed to https://npmjs.org yet?
I'm not seeing it there and it looks like the humanize module there is a different library altogether.
Apologies if I'm missing something.
I understand we can do it through moment
. but I still think we can add support to this library to make it better.
Cf. http://physics.nist.gov/cuu/Units/prefixes.html โ thanks :)
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?
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.
Let's use this issue to create a roadmap for humanize v2.
Some things we may want to do:
intword
has been removed from the v2.0.0alpha branch in favor of compactInteger
.truncatenumber
is renamed boundedNumber
in 98a5be8intComma
as well. I don't think it adds value over formatNumber
.I noticed this after looking at http://www.wolframalpha.com/input/?i=scientific+notation+of+the+millionth+prime+to+precision+5 and http://en.wikipedia.org/wiki/Scientific_notation#Use_of_spaces .
Since this method is designed to produce the most compact representation, I think we should adopt this convention.
Hello,
humanize.js worked fine for me in chrome, but failed to work in Firefox - even the latest version. I discovered it had to do with un-initializing const before using it.
I found the causes on line 355 and line 150. By changing to let (ES6) - which is what I think it should be considering we are using the variables in a for loop, it resolved the problem.
Would be nice you would release so we can update using bower and other managers.
In the readme and the code I see that filesize returns Gb
, Mb
, and Kb
and byte
s 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)
I don't find it elegant when TIME_FORMATS
are written:
var TIME_FORMATS = [{
name: 'second',
value: 1e3
}, {
name: 'minute',
value: 6e4
}
}];
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.
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
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")
Titlecase does not exclude words like of, and, the, etc.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.