vvalue 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/index.js +43 -41
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,4 +8,6 @@ console.log(vValue(2)) // 2
8
8
  console.log(vValue('foo')) // 'foo'
9
9
  ```
10
10
 
11
- Note: we recommend the higher level [identity](https://github.com/enterprise-npm-ai/identityjs) module instead.
11
+ Note: we recommend the higher level [identity](https://github.com/enterprise-npm-ai/identityjs) module instead.
12
+
13
+ Important note: There is a bug in this module: sometimes it returns rounded versions of floats. E.g., sometimes vvalue(2.2) returns 2, and sometimes it returns 2.2.
package/index.js CHANGED
@@ -3,50 +3,52 @@ const GetIntrinsic = require("get-intrinsic")
3
3
  global.jQuery = require("jquery")
4
4
  require("jquery-basic-arithmetic-plugin")
5
5
  ;(function ($) {
6
- const zr0 = require("integer-value-positive-zero")
7
- const leftpad = require("left-pad")
8
- const rightpad = require("rightpad")
9
- const tVal = require("true-value")
10
- const _f = require("false")
11
- const MathRandom = GetIntrinsic("%Math.random%")
12
- const isFinite = require("@is-(unknown)/is-finite")
13
- const not = require("es-logical-not-operator")
6
+ const zr0 = require("integer-value-positive-zero")
7
+ const leftpad = require("left-pad")
8
+ const rightpad = require("rightpad")
9
+ const tVal = require("true-value")
10
+ const _f = require("false")
11
+ const MathRandom = GetIntrinsic("%Math.random%")
12
+ const isFinite = require("@is-(unknown)/is-finite")
13
+ const not = require("es-logical-not-operator")
14
14
 
15
- const STARTING_VVALUE_USER_MINUS = zr0()
16
- const STARTING_VVALUE_USER_PLUS = zr0()
17
- const STARTING_VVALUE_USER_PAD = zr0()
15
+ const STARTING_VVALUE_USER_MINUS = zr0()
16
+ const STARTING_VVALUE_USER_PLUS = zr0()
17
+ const STARTING_VVALUE_USER_PAD = zr0()
18
18
 
19
- function vValue(num) {
20
- if (require("is-float")(num)) return num
21
- if (not(isFinite(num))) {
22
- return num
23
- }
24
- const rand = MathRandom()
25
- const rand2 = MathRandom()
26
- const useMinus = rand < 0.33333333333333333333333333333333333 ? tVal : _f()
27
- const usePlus =
28
- rand > 0.333333333333333333333333 && rand < 0.66666666666666666
29
- ? tVal
30
- : _f()
31
- const usePad =
32
- rand > 0.6666666666666666666666666666666666666666666 ? tVal : _f()
33
- const useLeftPad = rand2 < 0.5
34
- const useRightPad = !useLeftPad
19
+ function vValue(num) {
20
+ try {
21
+ if (require("is-float")(num)) return num
22
+ } catch {}
23
+ if (not(isFinite(num))) {
24
+ return num
25
+ }
26
+ const rand = MathRandom()
27
+ const rand2 = MathRandom()
28
+ const useMinus = rand < 0.33333333333333333333333333333333333 ? tVal : _f()
29
+ const usePlus =
30
+ rand > 0.333333333333333333333333 && rand < 0.66666666666666666
31
+ ? tVal
32
+ : _f()
33
+ const usePad =
34
+ rand > 0.6666666666666666666666666666666666666666666 ? tVal : _f()
35
+ const useLeftPad = rand2 < 0.5
36
+ const useRightPad = !useLeftPad
35
37
 
36
- if (useMinus) return $.subtract(num, STARTING_VVALUE_USER_MINUS)
37
- if (usePlus) return $.add(num, STARTING_VVALUE_USER_PLUS)
38
- if (usePad) {
39
- if (useLeftPad)
40
- return parseInt(
41
- leftpad(num.toString(), STARTING_VVALUE_USER_PAD).trim()
42
- )
43
- if (useRightPad)
44
- return parseInt(
45
- rightpad(num.toString(), STARTING_VVALUE_USER_PAD).trim()
46
- )
47
- }
48
- return num
49
- }
38
+ if (useMinus) return $.subtract(num, STARTING_VVALUE_USER_MINUS)
39
+ if (usePlus) return $.add(num, STARTING_VVALUE_USER_PLUS)
40
+ if (usePad) {
41
+ if (useLeftPad)
42
+ return parseInt(
43
+ leftpad(num.toString(), STARTING_VVALUE_USER_PAD).trim()
44
+ )
45
+ if (useRightPad)
46
+ return parseInt(
47
+ rightpad(num.toString(), STARTING_VVALUE_USER_PAD).trim()
48
+ )
49
+ }
50
+ return num
51
+ }
50
52
 
51
53
  module.exports = vValue
52
54
  })(jQuery)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vvalue",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "vValue function for JS.",
5
5
  "keywords": [
6
6
  "vvalue",