### Install Clj-Commons Humanize Library Source: https://context7.com/clj-commons/humanize/llms.txt Instructions for adding the Clj-Commons Humanize library to your Clojure or ClojureScript project using either `deps.edn` or Leiningen. ```clojure ;; deps.edn {:deps {org.clj-commons/humanize {:mvn/version "1.1"}}} ;; Leiningen [org.clj-commons/humanize "1.1"] ``` -------------------------------- ### Format integer with commas (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Converts an integer to a string with commas inserted every three digits for better readability. For example, 1000000 becomes '1,000,000'. Requires the 'clj-commons.humanize' namespace. ```clojure user> (h/intcomma 1000) "1,000" user> (h/intcomma 10123) "10,123" user> (h/intcomma 10311) "10,311" user> (h/intcomma 1000000) "1,000,000" ``` -------------------------------- ### Convert number to word string (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Converts an integer into its written-out string form. For example, 23237897 becomes 'twenty-three million two hundred and thirty-seven thousand eight hundred and ninety-seven'. Requires the 'clj-commons.humanize' namespace. ```clojure user> (require '[clj-commons.humanize :as h]) nil user> (h/numberword 3567) "three thousand five hundred and sixty-seven" user> (h/numberword 25223) "twenty-five thousand two hundred and twenty-three" user> (h/numberword 23237897) "twenty-three million two hundred and thirty-seven thousand eight hundred and ninety-seven" ``` -------------------------------- ### Build and deploy artifacts Source: https://github.com/clj-commons/humanize/blob/master/README.md Commands to build project JAR files and deploy them to Clojars. Supports snapshot and release deployment modes. ```clojure clojure -T:build jar clojure -T:build deploy clojure -T:build deploy :release true ``` -------------------------------- ### Lint project source code Source: https://github.com/clj-commons/humanize/blob/master/README.md Uses clj-kondo to perform static analysis and linting on the project source files. ```bash clj -M:clj-kondo --lint src ``` -------------------------------- ### Run project tests Source: https://github.com/clj-commons/humanize/blob/master/README.md Executes test suites for JVM or ClojureScript environments. ClojureScript testing requires Karma and specific browser launchers. ```bash clojure -X:test npm install -g karma karma-cljs-test karma-chrome-launcher karma-firefox-launcher clojure -M:cljs-test -x chrome-headless ``` -------------------------------- ### Format Filesize in Human-Readable Units (filesize) Source: https://context7.com/clj-commons/humanize/llms.txt Formats a number of bytes into a human-readable string using either decimal (KB, MB, GB) or binary (KiB, MiB, GiB) suffixes. Allows customization of numeric precision via the `:format` option. ```clojure (require '[clj-commons.humanize :as h]) ;; Decimal suffixes (default) (h/filesize 0) ;; => "0" (h/filesize 1000) ;; => "1.0KB" (h/filesize 3000000) ;; => "3.0MB" (h/filesize 3000000000) ;; => "3.0GB" (h/filesize 3000000000000) ;; => "3.0TB" ;; Binary suffixes (1024-based) (h/filesize 1024 :binary true) ;; => "1.0KiB" (h/filesize 3000000 :binary true) ;; => "2.9MiB" ;; Custom format with more precision (h/filesize 3000 :binary true :format "%.2f") ;; => "2.93KiB" (h/filesize 1536000 :binary false :format "%.3f") ;; => "1.536MB" ``` -------------------------------- ### Format bytes as human-readable filesize (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Formats a number of bytes into a human-readable string using standard (kB, MB) or binary (KiB, MiB) suffixes. Allows custom formatting of the numeric part. Requires the 'clj-commons.humanize' namespace. ```clojure user> (h/filesize 3000000 :binary false) "3.0MB" user> (h/filesize 3000000000000 :binary false) "3.0TB" user> (h/filesize 3000 :binary true :format "%.2f") "2.93KiB" user> (h/filesize 3000000 :binary true) "2.9MiB" ``` -------------------------------- ### Format duration into human-readable string Source: https://github.com/clj-commons/humanize/blob/master/README.md Converts a duration in milliseconds into a human-friendly string representation. Supports optional configuration maps for custom number formatting. ```clojure (h/duration 2000) (h/duration 325100) (h/duration 500) (h/duration 325100 {:number-format str}) ``` -------------------------------- ### Format Duration in Milliseconds to Human-Readable String (Clojure) Source: https://context7.com/clj-commons/humanize/llms.txt Converts a duration in milliseconds to a human-readable string. Supports various time units and offers options for numeric formatting, custom short text for sub-second durations, and list formatting like the Oxford comma. Requires clj-commons.humanize. ```clojure (require '[clj-commons.humanize :as h]) ;; Basic durations (h/duration 500) ;; => "less than a second" (h/duration 1000) ;; => "one second" (h/duration 2000) ;; => "two seconds" (h/duration 60000) ;; => "one minute" (h/duration 325100) ;; => "five minutes, twenty-five seconds" (h/duration 3600000) ;; => "one hour" (h/duration 3725000) ;; => "one hour, two minutes, five seconds" (h/duration 86400000) ;; => "one day" (h/duration 90061000) ;; => "one day, one hour, one minute, one second" ;; Longer durations (h/duration 604800000) ;; => "one week" (h/duration 2678400000) ;; => "one month" (h/duration 31536000000) ;; => "one year" ;; Use numeric format instead of words (h/duration 325100 {:number-format str}) ;; => "5 minutes, 25 seconds" ;; Custom short text for sub-second durations (h/duration 100 {:short-text "instant"}) ;; => "instant" ;; Use oxford comma format for lists (h/duration 90061000 {:list-format h/oxford}) ;; => "one day, one hour, one minute, and one second" ``` -------------------------------- ### Format list with Oxford comma (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Converts a list of items into a human-readable string, using an Oxford comma for lists of three or more items. Supports limiting the number of displayed items and custom formatting. Requires the 'clj-commons.humanize' namespace. ```clojure user> (h/oxford ["apple" "orange" "mango"]) "apple, orange, and mango" user> (h/oxford ["apple" "orange" "mango" "pear"] :maximum-display 2) "apple, orange, and 2 others" user> (h/oxford ["apple" "orange" "mango" "pear"] :maximum-display 2 :truncate-noun "fruit") "apple, orange, and 2 other fruits" user> (h/oxford ["apple" "orange" "mango" "pear"] :maximum-display 2 :number-format h/numberword :truncate-noun "fruit") "apple, orange, and two other fruits" ``` -------------------------------- ### Format Integer with Commas (intcomma) Source: https://context7.com/clj-commons/humanize/llms.txt Formats an integer into a string with commas as thousands separators. This function handles both positive and negative integers, improving readability for large numbers. ```clojure (require '[clj-commons.humanize :as h]) (h/intcomma 1000) ;; => "1,000" (h/intcomma 10123) ;; => "10,123" (h/intcomma 1000000) ;; => "1,000,000" (h/intcomma 1234567890) ;; => "1,234,567,890" (h/intcomma -50000) ;; => "-50,000" ``` -------------------------------- ### Convert Number to Written English Form (numberword) Source: https://context7.com/clj-commons/humanize/llms.txt Converts an integer into its full English word representation. Handles numbers from zero up to millions, ensuring correct grammar, hyphenation, and 'and' usage. ```clojure (require '[clj-commons.humanize :as h]) ;; Basic number conversion (h/numberword 0) ;; => "zero" (h/numberword 42) ;; => "forty-two" (h/numberword 100) ;; => "one hundred" (h/numberword 123) ;; => "one hundred and twenty-three" (h/numberword 1000) ;; => "one thousand" (h/numberword 3567) ;; => "three thousand five hundred and sixty-seven" (h/numberword 25223) ;; => "twenty-five thousand two hundred and twenty-three" (h/numberword 23237897) ;; => "twenty-three million two hundred and thirty-seven thousand eight hundred and ninety-seven" ``` -------------------------------- ### Convert Large Integer to Friendly Text (intword) Source: https://context7.com/clj-commons/humanize/llms.txt Converts large integers into a more readable text format using magnitude suffixes like million, billion, etc. It supports numbers up to decillion and allows custom decimal formatting. ```clojure (require '[clj-commons.humanize :as h]) (h/intword 1000000) ;; => "1.0 million" (h/intword 1200000) ;; => "1.2 million" (h/intword 2000000000) ;; => "2.0 billion" (h/intword 6000000000000) ;; => "6.0 trillion" (h/intword 3500000000000000000000N) ;; => "3.5 sextillion" (h/intword 8100000000000000000000000000000000N) ;; => "8.1 decillion" ;; Custom format with more decimal places (h/intword 1234567 :format "%.2f") ;; => "1.23 million" ``` -------------------------------- ### Format Datetime to Human-Friendly String (Clojure) Source: https://context7.com/clj-commons/humanize/llms.txt Converts a datetime object to a human-friendly representation of the time elapsed relative to now. Supports past and future times, custom prefixes/suffixes, and can parse date strings. Requires Java Time APIs for Clojure. ```clojure (require '[clj-commons.humanize :as h]) (import '[java.time LocalDateTime] '[java.time.temporal ChronoUnit]) ;; Past times (h/datetime (.minusSeconds (LocalDateTime/now) 30)) ;; => "30 seconds ago" (h/datetime (.minusMinutes (LocalDateTime/now) 5)) ;; => "5 minutes ago" (h/datetime (.minusHours (LocalDateTime/now) 2)) ;; => "2 hours ago" (h/datetime (.minusDays (LocalDateTime/now) 3)) ;; => "3 days ago" (h/datetime (.minusWeeks (LocalDateTime/now) 2)) ;; => "2 weeks ago" (h/datetime (.minus (LocalDateTime/now) 3 ChronoUnit/MONTHS)) ;; => "3 months ago" (h/datetime (.minusYears (LocalDateTime/now) 7)) ;; => "7 years ago" (h/datetime (.minus (LocalDateTime/now) 20 ChronoUnit/YEARS)) ;; => "2 decades ago" ;; Future times (h/datetime (.plusSeconds (LocalDateTime/now) 30)) ;; => "in 30 seconds" (h/datetime (.plusDays (LocalDateTime/now) 5)) ;; => "in 5 days" (h/datetime (.plusYears (LocalDateTime/now) 2)) ;; => "in 2 years" ;; Custom prefix/suffix (h/datetime (.minusDays (LocalDateTime/now) 3) :suffix "before") ;; => "3 days before" (h/datetime (.plusDays (LocalDateTime/now) 3) :prefix "within") ;; => "within 3 days" ;; Custom reference time (def reference-time (LocalDateTime/of 2024 1 15 12 0 0)) (def event-time (LocalDateTime/of 2024 1 10 12 0 0)) (h/datetime event-time :now-dt reference-time) ;; => "5 days ago" ;; Works with date strings (ISO 8601 format) (h/datetime "2024-01-15T10:30:00" :now-dt (LocalDateTime/of 2024 1 15 10 30 30)) ;; => "30 seconds ago" ;; Works with date-only strings (h/datetime "2024-01-10" :now-dt (LocalDateTime/of 2024 1 15 12 0 0)) ;; => "5 days ago" ``` -------------------------------- ### Extend pluralization rules in Clojure Source: https://context7.com/clj-commons/humanize/llms.txt Allows developers to register custom pluralization rules or specific singular-to-plural exceptions. Rules are evaluated in order, and exceptions take precedence over standard rules. ```clojure (require '[clj-commons.humanize.inflect :as inflect]) ;; Add a custom rule (inflect/add-pluralize-noun-rule "Latin nouns ending in us" (fn [noun] (clojure.string/ends-with? noun "us")) (fn [noun] (str (subs noun 0 (- (count noun) 2)) "i"))) ;; Add custom exceptions (inflect/add-pluralize-noun-exceptions "Technical terms" {"matrix" "matrices"}) ``` -------------------------------- ### Convert large integer to friendly text (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Converts large integers into a more readable text format, using suffixes like million, billion, trillion, etc. It supports numbers up to decillion and googol. Works best for numbers over 1 million. Requires the 'clj-commons.humanize' namespace. ```clojure user> (h/intword 2000000000) "2.0 billion" user> (h/intword 6000000000000) "6.0 trillion" user> (h/intword 3500000000000000000000N) "3.5 sextillion" user> (h/intword 8100000000000000000000000000000000N) "8.1 decillion" ``` -------------------------------- ### Convert integer to ordinal string (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Converts an integer into its ordinal string representation (e.g., 1 becomes '1st', 2 becomes '2nd', 4 becomes '4th'). Requires the 'clj-commons.humanize' namespace. ```clojure user> (h/ordinal 1) "1st" user> (h/ordinal 2) "2nd" user> (h/ordinal 4) "4th" user> (h/ordinal 11) "11th" user> (h/ordinal 111) "111th" ``` -------------------------------- ### Format datetime difference (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Given a datetime or date, returns a human-friendly string representing the time difference relative to the current time (e.g., '30 seconds ago', 'in 2 decades'). Requires the 'clj-commons.humanize' namespace and Java's time API. ```clojure user> (import '(java.time LocalDateTime) '(java.time.temporal ChronoUnit)) java.time.temporal.ChronoUnit user> (h/datetime (.plusSeconds (LocalDateTime/now) -30)) "30 seconds ago" user> (h/datetime (.plusSeconds (LocalDateTime/now) 30)) "in 30 seconds" user> (h/datetime (.plus (LocalDateTime/now) -20 ChronoUnit/YEARS)) "2 decades ago" user> (h/datetime (.plus (LocalDateTime/now) -7 ChronoUnit/YEARS)) "7 years ago" ``` -------------------------------- ### Truncate String with Suffix (truncate) Source: https://context7.com/clj-commons/humanize/llms.txt Truncates a given string to a specified maximum length, appending a suffix (default is ellipsis '…'). The total length includes the suffix, ensuring the output does not exceed the specified limit. ```clojure (require '[clj-commons.humanize :as h]) ;; Default ellipsis suffix (…) (h/truncate "abcdefghijklmnopqrstuvwxyz" 10) ;; => "abcdefghi…" ;; Custom suffix (h/truncate "abcdefghijklmnopqrstuvwxyz" 10 "...") ;; => "abcdefg..." (h/truncate "abcdefghijklmnopqrstuvwxyz" 10 "[more]") ;; => "abcd[more]" ;; String shorter than length returns unchanged (h/truncate "hello" 10) ;; => "hello" ;; Practical example (h/truncate "This is a very long description that needs to be shortened" 30) ;; => "This is a very long descripti…" ``` -------------------------------- ### Pluralize nouns in Clojure Source: https://context7.com/clj-commons/humanize/llms.txt Returns the pluralized form of a noun based on a count. It handles standard English rules, irregular nouns, and specific suffix patterns. ```clojure (require '[clj-commons.humanize.inflect :as inflect]) (inflect/pluralize-noun 2 "city") ;; => "cities" (inflect/pluralize-noun 5 "person") ;; => "people" ``` -------------------------------- ### Convert Integer to Ordinal String (ordinal) Source: https://context7.com/clj-commons/humanize/llms.txt Converts an integer into its English ordinal string representation (e.g., 1st, 2nd, 3rd). It correctly handles common English ordinal rules and exceptions for numbers ending in 11, 12, and 13. ```clojure (require '[clj-commons.humanize :as h]) (h/ordinal 1) ;; => "1st" (h/ordinal 2) ;; => "2nd" (h/ordinal 3) ;; => "3rd" (h/ordinal 4) ;; => "4th" (h/ordinal 11) ;; => "11th" (h/ordinal 12) ;; => "12th" (h/ordinal 13) ;; => "13th" (h/ordinal 21) ;; => "21st" (h/ordinal 22) ;; => "22nd" (h/ordinal 111) ;; => "111th" (h/ordinal 112) ;; => "112th" ``` -------------------------------- ### Truncate string with suffix (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Truncates a string if it exceeds a specified length, appending a suffix (ellipsis by default) or a custom string. Requires the 'clj-commons.humanize' namespace. ```clojure user> (h/truncate "abcdefghijklmnopqrstuvwxyz" 10) "abcdefg..." user> (h/truncate "abcdefghijklmnopqrstuvwxyz" 10 "[more]") "abcd[more]" ``` -------------------------------- ### Pluralize noun based on count (Clojure) Source: https://github.com/clj-commons/humanize/blob/master/README.md Returns the plural form of a noun if the given count is not 1. Handles irregular plurals. Requires the 'clj-commons.humanize.inflect' namespace. ```clojure user (require '[clj-commons.humanize.inflect :as i]) nil user> (i/pluralize-noun 2 "thief") "thieves" user> (i/pluralize-noun 3 "tomato") "tomatoes" user> (i/pluralize-noun 4 "roof") "roofs" user> (i/pluralize-noun 5 "person") "people" user> (i/pluralize-noun 6 "buzz") "buzzes" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.