clj-commons / humanize Goto Github PK
View Code? Open in Web Editor NEWProduce human readable strings in clojure
License: Eclipse Public License 1.0
Produce human readable strings in clojure
License: Eclipse Public License 1.0
Hi,
Thanks for this library. It's really useful. I was just chatting with a colleague about producing a list with an oxford comma using butlast
. Then I found this, which is excellent.
I just noticed that the output for 2 items is:
(oxford ["apple" "orange"]) --> "apple, and orange"
when there should be no comma when there are only 2 items in the list.
From PR-31:
One thing I will say about this project: using
clojure.*
for a non-official project is a big no-no, and usingclojure.contrib.*
doubly so, so when this library gets overhauled, I would strongly recommend changing the top-level namespace.
I agree with this assessment by @seancorfield and think it would appropriate to change the top-level ns for this project.
Since it is planned to move to clj-commons, maybe the following:
clojure.contrib.humanize
--> clj-commons.humanize.core
clojure.contrib.inflect
--> clj-commons.humanize.inflect
clojure.contrib.macros
--> removed by PR-31Is there a way to use this lib in a multi-language application? E.g. to specify another word than and
when using the oxford
function?
In cljs env with the following versions:
org.clj-commons/humanize {:mvn/version "1.0"}
thheller/shadow-cljs {:mvn/version "2.25.5"}
tick/tick {:mvn/version "0.6.2"}
running any one of:
(h/datetime)
(h/datetime (js/Date.))
(require '[tick.core :as t])
(h/datetime (t/now))
results in the same exception:
(h/datetime)
:repl/exception!
;
; Execution error (ExceptionInfo) at (<cljs repl>:1).
; unable to coerce to java.time.LocalDateTime
I'm pretty sure that this:
(filesize 0)
shouldn't trigger IllegalArgumentException Value out of range for int: -1317624576693539402 clojure.lang.RT.intCast
.
Hi!
We use your lib at work, and it works great. Clojure 1.11 is now released and we're updating our dependencies to work with that, namely not importing abs
and so on.
Would you be interested in merging a PR with those updates if I make one?
There was an earlier attempt (#31) but that clashes with namespace renames and reorganizations.
Hi,
I love the idea of the library. I just tried bringing it in though and I see lein grabbing clj-time
0.12.0. We're already bringing in 0.15.2. This sounds just dicey enough to keep me from using the library.
It'd be nice just to give things a once-over and publish a current version.
Let me know if I could help.
oxford
doesn't seem to actually use an oxford comma. I believe the correct output would be:
user> (clojure.contrib.humanize/oxford ["apple" "orange" "mango"])
"apple, orange, and mango"
(Note the comma after orange
:) )
It would be nice to have clojurescript support as UIs can really benefit from this library.
With clojure 1.7+ using reader conditionals this can be done.
The tests are passing for both clj and cljs.
Should I do some cleanup and make a PR?
In clojure.contrib.inflect
, *pluralize-noun-rules*
and *pluralize-noun-exceptions*
are ^:dynamic, but their root values are never rewritten, instead the atoms inside the reference are rewritten. Is this intentional? If not, they can be converted to ordinary, non-dynamic, non-earmuff vars.
create a new project:
lein new app humanize-bug
add clojure-humanize and clj-time deps to project.clj
:dependencies [
[org.clojure/clojure "1.8.0"]
[clojure-humanize "0.1.0"]
[clj-time "0.11.0"]
]
require humanize in core.clj:
(ns humanize-bug.core
(:gen-class)
(:require [clojure.contrib.humanize :refer [truncate]]))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println (truncate (first args) 5)))
lein run "hello world"
expected:
he...
actual:
Exception in thread "main" java.lang.IllegalStateException: to-local-date-time already refers to: #'clj-time.local/to-local-date-time in namespace: clojure.contrib.humanize, compiling:(clojure/contrib/humanize.clj:1:1)
Just to let you know:
https://clojars.org/clojure-humanize
I.e. positive time diffs, like in: "in a moment", "tomorrow", "in 2 days", "next week", or similar.
I like where you're going with this library. Here are some suggestions to help improve it.
The plural of "chief" is "chiefs", not "chieves".
user> (clojure.contrib.inflect/pluralize-noun 2 "chief" )
"chieves"
On a separate note, there is a spelling mistake in the README examples. This
user> (clojure.contrib.inflect/pluralize-noun 2 "theif" )
"theives"
Should be
user> (clojure.contrib.inflect/pluralize-noun 2 "thief" )
"thieves"
An additional option should be able to enable output such as apple, orange, and five other fruits
.
Let's release 0.1.1 which will resolve 11.
Here's a bit of code I use to humanize an elapsed period of time:
(def ^:private humanized-periods
[[(* 1000 60 60 24 7) "week"]
[(* 1000 60 60 24) "day"]
[(* 1000 60 60) "hour"]
[(* 1000 60) "minute"]
[1000 "second"]])
(defn humanize-ellapsed-ms
[ms]
(let [periods (loop [remainder ms
[[period-ms period-name] & more-periods] humanized-periods
terms []]
(cond-let
(nil? period-ms)
terms
(< remainder period-ms)
(recur remainder more-periods terms)
:else
(let
[period-count (int (/ remainder period-ms))
next-remainder (mod remainder period-ms)
formatted (str period-count " " period-name
(when-not (= 1 period-count) "s"))]
(recur next-remainder
more-periods
(conj terms formatted)))))]
(str/join ", " periods)))
cond-let is from io.aviso/toolchest.
Hi,
Would you be so kind of release a non-snapshot version to clojars? We would like to include your library in a project but we cannot use any snapshot dependencies on production.
Thanks,
Daniel
Thanks a ton for your work on Clojure-humanize!
I just saw that the "duration" function has been recently added to version 0.2.1 . I was just wondering if there is anything blocking you from release this version to Clojars. I will be happy to help if there is something that I can do to help
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.