Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[decimal] Add support for decimal.js package #2123

Merged
merged 7 commits into from Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions decimal/README.md
@@ -0,0 +1,54 @@
# cljsjs/decimal

[](dependency)
```clojure
[cljsjs/decimal "10.2.0-0"] ;; latest release
```
[](/dependency)

This jar comes with `deps.cljs` as used by the [Foreign Libs][flibs] feature
of the ClojureScript compiler. After adding the above dependency to your project
you can require the packaged library like so:

```clojure
(ns application.core
(:require cljsjs.decimal))
```

This package also supports `:global-exports`:

```clojure
(ns application.core
(:require ["decimal.js" :as decimal]))
```

The library is similar to [bignumber.js][bignumber], but here precision is
specified in terms of significant digits rather than decimal places, and all
calculations are rounded to the precision (similar to Python's decimal module)
rather than just those involving division.

This library also adds the trigonometric functions, among others, and supports
non-integer powers, which makes it a significantly larger library than
[bignumber.js][bignumber] and the even smaller [big.js][big].

Example usage from Clojurescript:

```clojure
(ns example.core
(:require ["decimal.js" :as decimal]))

(extend-type decimal
IEquiv
(-equiv [this other]
(.equals this other)))

(let [x (decimal. 123.4567)
y (decimal. "123456.7e-3")
z (decimal. x)]
(= x y z))
;; => true
```

[flibs]: https://clojurescript.org/reference/packaging-foreign-deps
[bignumber]: https://github.com/MikeMcl/bignumber.js/
[big]: https://github.com/MikeMcl/big.js/
4 changes: 4 additions & 0 deletions decimal/boot-cljsjs-checksums.edn
@@ -0,0 +1,4 @@
{"cljsjs/decimal/development/decimal.inc.js"
"D836AD18A62A9901385A09457286F1A4",
"cljsjs/decimal/production/decimal.min.inc.js"
"D9A9AE5A5F6D464B9DC73E64624F21E4"}
39 changes: 39 additions & 0 deletions decimal/build.boot
@@ -0,0 +1,39 @@
(set-env!
:resource-paths #{"resources"}
:dependencies '[[cljsjs/boot-cljsjs "0.10.5" :scope "test"]])

(require '[cljsjs.boot-cljsjs.packaging :refer :all])

(def +lib-version+ "10.2.0")
(def +version+ (str +lib-version+ "-0"))

(task-options!
push {:ensure-clean false}
pom {:project 'cljsjs/decimal
:version +version+
:description "An arbitrary-precision Decimal type for JavaScript."
:url "http://mikemcl.github.io/decimal.js"
:license {"MIT" "http://opensource.org/licenses/MIT"}
:scm {:url "https://github.com/cljsjs/packages"}})

(deftask build-decimal []
(run-commands :commands [["npm" "install" "--include-dev"]
["npm" "run" "bundle"]
["npm" "run" "generate-extern"]
["rm" "-rf" "./node_modules"]]))

(deftask package []
(comp
(build-decimal)
(sift :move {#".*decimal.bundle.js" "cljsjs/decimal/development/decimal.inc.js"
#".*decimal.ext.js" "cljsjs/decimal/common/decimal.ext.js"})
(minify :in "cljsjs/decimal/development/decimal.inc.js"
:out "cljsjs/decimal/production/decimal.min.inc.js")
(sift :include #{#"^cljsjs"})
(deps-cljs :provides ["decimal.js", "cljsjs.decimal"]
:requires []
:global-exports '{decimal.js Decimal
cljsjs.decimal Decimal})
(pom)
(jar)
(validate-checksums)))
42 changes: 42 additions & 0 deletions decimal/resources/package.json
@@ -0,0 +1,42 @@
{
"name": "decimal.js",
"homepage": "https://github.com/MikeMcl/decimal.js",
"bugs": "https://github.com/MikeMcl/decimal.js/issues",
"description": "An arbitrary-precision Decimal type for JavaScript.",
"version": "10.2.0",
"keywords": [
"arbitrary",
"precision",
"arithmetic",
"big",
"number",
"decimal",
"float",
"biginteger",
"bigdecimal",
"bignumber",
"bigint",
"bignum"
],
"repository" : {
"type": "git",
"url": "https://github.com/MikeMcl/decimal.js.git"
},
"author": {
"name": "Michael Mclaughlin",
"email": "M8ch88l@gmail.com"
},
"license": "MIT",
"dependencies": {
"decimal.js": "^10.2.0"
},
"devDependencies": {
"cross-env": "^3.1.4",
"browserify": "^15.1.0",
"externs-generator": "^0.3.3"
},
"scripts": {
"bundle": "cross-env NODE_ENV=production browserify ./node_modules/decimal.js/decimal.js -s Decimal -o decimal.bundle.js",
"generate-extern": "generate-extern -f decimal.bundle.js -n Decimal -o decimal.ext.js"
}
}