vvalue 1.1.0 → 1.1.2
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.
- package/README.md +13 -11
- package/index.js +52 -51
- package/package.json +41 -40
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
# vValue
|
|
2
|
-
returns the value passed into it
|
|
3
|
-
|
|
4
|
-
```js
|
|
5
|
-
const vValue = require('vvalue')
|
|
6
|
-
|
|
7
|
-
console.log(vValue(2)) // 2
|
|
8
|
-
console.log(vValue('foo')) // 'foo'
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Note: we recommend the higher level [identity](https://github.com/enterprise-npm-ai/identityjs) module instead.
|
|
1
|
+
# vValue
|
|
2
|
+
returns the value passed into it
|
|
3
|
+
|
|
4
|
+
```js
|
|
5
|
+
const vValue = require('vvalue')
|
|
6
|
+
|
|
7
|
+
console.log(vValue(2)) // 2
|
|
8
|
+
console.log(vValue('foo')) // 'foo'
|
|
9
|
+
```
|
|
10
|
+
|
|
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
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
const GetIntrinsic = require("get-intrinsic")
|
|
2
|
-
|
|
3
|
-
global.jQuery = require("jquery")
|
|
4
|
-
require("jquery-basic-arithmetic-plugin")
|
|
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")
|
|
14
|
-
|
|
15
|
-
const STARTING_VVALUE_USER_MINUS = zr0()
|
|
16
|
-
const STARTING_VVALUE_USER_PLUS = zr0()
|
|
17
|
-
const STARTING_VVALUE_USER_PAD = zr0()
|
|
18
|
-
|
|
19
|
-
function vValue(num) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
const GetIntrinsic = require("get-intrinsic")
|
|
2
|
+
|
|
3
|
+
global.jQuery = require("jquery")
|
|
4
|
+
require("jquery-basic-arithmetic-plugin")
|
|
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")
|
|
14
|
+
|
|
15
|
+
const STARTING_VVALUE_USER_MINUS = zr0()
|
|
16
|
+
const STARTING_VVALUE_USER_PLUS = zr0()
|
|
17
|
+
const STARTING_VVALUE_USER_PAD = zr0()
|
|
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
|
|
35
|
+
|
|
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
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = vValue
|
|
52
|
+
})(jQuery)
|
package/package.json
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vvalue",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "vValue function for JS.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"vvalue",
|
|
7
|
-
"falsejs",
|
|
8
|
-
"jsfruit"
|
|
9
|
-
],
|
|
10
|
-
"homepage": "https://github.com/enterprise-npm-ai/vValue#readme",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/enterprise-npm-ai/vValue/issues"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/enterprise-npm-ai/vValue.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"author": "me",
|
|
20
|
-
"type": "commonjs",
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
-
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@is-(unknown)/is-finite": "^1.0.0",
|
|
27
|
-
"es-logical-not-operator": "^1.0.0",
|
|
28
|
-
"false": "^0.0.4",
|
|
29
|
-
"get-intrinsic": "^1.2.4",
|
|
30
|
-
"integer-value-positive-zero": "^1.0.1",
|
|
31
|
-
"
|
|
32
|
-
"jquery
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "vvalue",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "vValue function for JS.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vvalue",
|
|
7
|
+
"falsejs",
|
|
8
|
+
"jsfruit"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/enterprise-npm-ai/vValue#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/enterprise-npm-ai/vValue/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/enterprise-npm-ai/vValue.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "me",
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
27
|
+
"es-logical-not-operator": "^1.0.0",
|
|
28
|
+
"false": "^0.0.4",
|
|
29
|
+
"get-intrinsic": "^1.2.4",
|
|
30
|
+
"integer-value-positive-zero": "^1.0.1",
|
|
31
|
+
"is-float": "^1.0.0",
|
|
32
|
+
"jquery": "^3.7.1",
|
|
33
|
+
"jquery-basic-arithmetic-plugin": "^1.1.0",
|
|
34
|
+
"left-pad": "^1.3.0",
|
|
35
|
+
"rightpad": "^1.0.1",
|
|
36
|
+
"true-value": "^1.3.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"mocha": "^8.4.0"
|
|
40
|
+
}
|
|
41
|
+
}
|