@common-fp/shared-internals 0.1.0

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 (123) hide show
  1. package/dist/a-or-an.cjs +6 -0
  2. package/dist/a-or-an.d.cts +2 -0
  3. package/dist/a-or-an.d.ts +1 -0
  4. package/dist/a-or-an.mjs +6 -0
  5. package/dist/assert-arg-has-values-of-type.cjs +29 -0
  6. package/dist/assert-arg-has-values-of-type.d.cts +2 -0
  7. package/dist/assert-arg-has-values-of-type.d.ts +1 -0
  8. package/dist/assert-arg-has-values-of-type.mjs +29 -0
  9. package/dist/assert-arg-is-array-of-accepted-types.cjs +28 -0
  10. package/dist/assert-arg-is-array-of-accepted-types.d.cts +2 -0
  11. package/dist/assert-arg-is-array-of-accepted-types.d.ts +1 -0
  12. package/dist/assert-arg-is-array-of-accepted-types.mjs +28 -0
  13. package/dist/assert-arg-is-array-of-same-type.cjs +34 -0
  14. package/dist/assert-arg-is-array-of-same-type.d.cts +2 -0
  15. package/dist/assert-arg-is-array-of-same-type.d.ts +1 -0
  16. package/dist/assert-arg-is-array-of-same-type.mjs +34 -0
  17. package/dist/assert-arg-is-array-of-type.cjs +18 -0
  18. package/dist/assert-arg-is-array-of-type.d.cts +2 -0
  19. package/dist/assert-arg-is-array-of-type.d.ts +1 -0
  20. package/dist/assert-arg-is-array-of-type.mjs +18 -0
  21. package/dist/assert-arg-is-char.cjs +19 -0
  22. package/dist/assert-arg-is-char.d.cts +2 -0
  23. package/dist/assert-arg-is-char.d.ts +1 -0
  24. package/dist/assert-arg-is-char.mjs +19 -0
  25. package/dist/assert-arg-is-int.cjs +35 -0
  26. package/dist/assert-arg-is-int.d.cts +2 -0
  27. package/dist/assert-arg-is-int.d.ts +1 -0
  28. package/dist/assert-arg-is-int.mjs +35 -0
  29. package/dist/assert-arg-is-one-of-type.cjs +17 -0
  30. package/dist/assert-arg-is-one-of-type.d.cts +2 -0
  31. package/dist/assert-arg-is-one-of-type.d.ts +1 -0
  32. package/dist/assert-arg-is-one-of-type.mjs +17 -0
  33. package/dist/assert-arg-is-type.cjs +12 -0
  34. package/dist/assert-arg-is-type.d.cts +2 -0
  35. package/dist/assert-arg-is-type.d.ts +1 -0
  36. package/dist/assert-arg-is-type.mjs +12 -0
  37. package/dist/assert-arg-shares-type-with.cjs +12 -0
  38. package/dist/assert-arg-shares-type-with.d.cts +2 -0
  39. package/dist/assert-arg-shares-type-with.d.ts +1 -0
  40. package/dist/assert-arg-shares-type-with.mjs +12 -0
  41. package/dist/assert-arg-type-is-one-of.cjs +14 -0
  42. package/dist/assert-arg-type-is-one-of.d.cts +2 -0
  43. package/dist/assert-arg-type-is-one-of.d.ts +1 -0
  44. package/dist/assert-arg-type-is-one-of.mjs +14 -0
  45. package/dist/common-types.cjs +39 -0
  46. package/dist/common-types.d.cts +2 -0
  47. package/dist/common-types.d.ts +1 -0
  48. package/dist/common-types.mjs +39 -0
  49. package/dist/contains-type.cjs +9 -0
  50. package/dist/contains-type.d.cts +2 -0
  51. package/dist/contains-type.d.ts +1 -0
  52. package/dist/contains-type.mjs +9 -0
  53. package/dist/deps/type-detect.cjs +153 -0
  54. package/dist/deps/type-detect.mjs +153 -0
  55. package/dist/deps/universal-eol.cjs +18 -0
  56. package/dist/deps/universal-eol.mjs +18 -0
  57. package/dist/ensure-number.cjs +10 -0
  58. package/dist/ensure-number.d.cts +2 -0
  59. package/dist/ensure-number.d.ts +1 -0
  60. package/dist/ensure-number.mjs +10 -0
  61. package/dist/ensure-set.cjs +12 -0
  62. package/dist/ensure-set.d.cts +2 -0
  63. package/dist/ensure-set.d.ts +1 -0
  64. package/dist/ensure-set.mjs +12 -0
  65. package/dist/eol.cjs +3 -0
  66. package/dist/eol.d.cts +2 -0
  67. package/dist/eol.d.ts +1 -0
  68. package/dist/eol.mjs +3 -0
  69. package/dist/get-fn-by-type.cjs +9 -0
  70. package/dist/get-fn-by-type.d.cts +2 -0
  71. package/dist/get-fn-by-type.d.ts +1 -0
  72. package/dist/get-fn-by-type.mjs +9 -0
  73. package/dist/get-fn.cjs +11 -0
  74. package/dist/get-fn.d.cts +2 -0
  75. package/dist/get-fn.d.ts +1 -0
  76. package/dist/get-fn.mjs +11 -0
  77. package/dist/get-iterator.cjs +23 -0
  78. package/dist/get-iterator.d.cts +2 -0
  79. package/dist/get-iterator.d.ts +1 -0
  80. package/dist/get-iterator.mjs +23 -0
  81. package/dist/get-random-int.cjs +5 -0
  82. package/dist/get-random-int.d.cts +2 -0
  83. package/dist/get-random-int.d.ts +1 -0
  84. package/dist/get-random-int.mjs +5 -0
  85. package/dist/get-type.cjs +5 -0
  86. package/dist/get-type.d.cts +2 -0
  87. package/dist/get-type.d.ts +1 -0
  88. package/dist/get-type.mjs +5 -0
  89. package/dist/index.cjs +30 -0
  90. package/dist/index.d.cts +2 -0
  91. package/dist/index.d.ts +1 -0
  92. package/dist/index.mjs +28 -0
  93. package/dist/negate.cjs +6 -0
  94. package/dist/negate.d.cts +2 -0
  95. package/dist/negate.d.ts +1 -0
  96. package/dist/negate.mjs +6 -0
  97. package/dist/to-english-list.cjs +12 -0
  98. package/dist/to-english-list.d.cts +2 -0
  99. package/dist/to-english-list.d.ts +1 -0
  100. package/dist/to-english-list.mjs +12 -0
  101. package/dist/truncate-to-n-chars.cjs +18 -0
  102. package/dist/truncate-to-n-chars.d.cts +2 -0
  103. package/dist/truncate-to-n-chars.d.ts +1 -0
  104. package/dist/truncate-to-n-chars.mjs +18 -0
  105. package/dist/validate-array-keys.cjs +19 -0
  106. package/dist/validate-array-keys.d.cts +2 -0
  107. package/dist/validate-array-keys.d.ts +1 -0
  108. package/dist/validate-array-keys.mjs +19 -0
  109. package/dist/validate-is-between-input.cjs +20 -0
  110. package/dist/validate-is-between-input.d.cts +2 -0
  111. package/dist/validate-is-between-input.d.ts +1 -0
  112. package/dist/validate-is-between-input.mjs +20 -0
  113. package/dist/validate-object-keys.cjs +13 -0
  114. package/dist/validate-object-keys.d.cts +2 -0
  115. package/dist/validate-object-keys.d.ts +1 -0
  116. package/dist/validate-object-keys.mjs +13 -0
  117. package/dist/validate-range.cjs +14 -0
  118. package/dist/validate-range.d.cts +2 -0
  119. package/dist/validate-range.d.ts +1 -0
  120. package/dist/validate-range.mjs +14 -0
  121. package/license.txt +106 -0
  122. package/package.json +39 -0
  123. package/readme.md +10 -0
@@ -0,0 +1,9 @@
1
+ /**
2
+ * a simple function taking either an array or set of expected types and
3
+ * returning whether it contains a specific type
4
+ */
5
+ const containsType = (expected, type) => {
6
+ return expected.includes ? expected.includes(type) : expected.has(type)
7
+ }
8
+
9
+ module.exports = containsType
@@ -0,0 +1,2 @@
1
+ import { default as containsType } from '@common-fp/shared-internals-types/contains-type'
2
+ export = containsType
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/contains-type'
@@ -0,0 +1,9 @@
1
+ /**
2
+ * a simple function taking either an array or set of expected types and
3
+ * returning whether it contains a specific type
4
+ */
5
+ const containsType = (expected, type) => {
6
+ return expected.includes ? expected.includes(type) : expected.has(type)
7
+ }
8
+
9
+ export default containsType
@@ -0,0 +1,153 @@
1
+ /**
2
+ * from github.com/chaijs/type-detect#4415ced2c49007f097627515806553e7f649c293Z
3
+ * no version indicated in package.json
4
+ * license from this commit is referenced in license.txt
5
+ */
6
+
7
+ const promiseExists = typeof Promise === 'function'
8
+ const globalObject = (Obj => {
9
+ if (typeof globalThis === 'object') {
10
+ return globalThis
11
+ }
12
+ Object.defineProperty(Obj, 'typeDetectGlobalObject', {
13
+ get() {
14
+ return this
15
+ },
16
+ configurable: true,
17
+ })
18
+ // eslint-disable-next-line no-undef
19
+ const global = typeDetectGlobalObject
20
+ delete Obj.typeDetectGlobalObject
21
+ return global
22
+ })(Object.prototype)
23
+ const symbolExists = typeof Symbol !== 'undefined'
24
+ const mapExists = typeof Map !== 'undefined'
25
+ const setExists = typeof Set !== 'undefined'
26
+ const weakMapExists = typeof WeakMap !== 'undefined'
27
+ const weakSetExists = typeof WeakSet !== 'undefined'
28
+ const dataViewExists = typeof DataView !== 'undefined'
29
+ const symbolIteratorExists =
30
+ symbolExists && typeof Symbol.iterator !== 'undefined'
31
+ const symbolToStringTagExists =
32
+ symbolExists && typeof Symbol.toStringTag !== 'undefined'
33
+ const setEntriesExists =
34
+ setExists && typeof Set.prototype.entries === 'function'
35
+ const mapEntriesExists =
36
+ mapExists && typeof Map.prototype.entries === 'function'
37
+ const setIteratorPrototype =
38
+ setEntriesExists && Object.getPrototypeOf(new Set().entries())
39
+ const mapIteratorPrototype =
40
+ mapEntriesExists && Object.getPrototypeOf(new Map().entries())
41
+ const arrayIteratorExists =
42
+ symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function'
43
+ const arrayIteratorPrototype =
44
+ arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]())
45
+ const stringIteratorExists =
46
+ symbolIteratorExists &&
47
+ typeof String.prototype[Symbol.iterator] === 'function'
48
+ const stringIteratorPrototype =
49
+ stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]())
50
+ const toStringLeftSliceLength = 8
51
+ const toStringRightSliceLength = -1
52
+ module.exports = function typeDetect(obj) {
53
+ const typeofObj = typeof obj
54
+ if (typeofObj !== 'object') {
55
+ return typeofObj
56
+ }
57
+ if (obj === null) {
58
+ return 'null'
59
+ }
60
+ if (obj === globalObject) {
61
+ return 'global'
62
+ }
63
+ if (
64
+ Array.isArray(obj) &&
65
+ (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
66
+ ) {
67
+ return 'Array'
68
+ }
69
+ if (typeof window === 'object' && window !== null) {
70
+ if (typeof window.location === 'object' && obj === window.location) {
71
+ return 'Location'
72
+ }
73
+ if (typeof window.document === 'object' && obj === window.document) {
74
+ return 'Document'
75
+ }
76
+ if (typeof window.navigator === 'object') {
77
+ if (
78
+ typeof window.navigator.mimeTypes === 'object' &&
79
+ obj === window.navigator.mimeTypes
80
+ ) {
81
+ return 'MimeTypeArray'
82
+ }
83
+ if (
84
+ typeof window.navigator.plugins === 'object' &&
85
+ obj === window.navigator.plugins
86
+ ) {
87
+ return 'PluginArray'
88
+ }
89
+ }
90
+ if (
91
+ (typeof window.HTMLElement === 'function' ||
92
+ typeof window.HTMLElement === 'object') &&
93
+ obj instanceof window.HTMLElement
94
+ ) {
95
+ if (obj.tagName === 'BLOCKQUOTE') {
96
+ return 'HTMLQuoteElement'
97
+ }
98
+ if (obj.tagName === 'TD') {
99
+ return 'HTMLTableDataCellElement'
100
+ }
101
+ if (obj.tagName === 'TH') {
102
+ return 'HTMLTableHeaderCellElement'
103
+ }
104
+ }
105
+ }
106
+ const stringTag = symbolToStringTagExists && obj[Symbol.toStringTag]
107
+ if (typeof stringTag === 'string') {
108
+ return stringTag
109
+ }
110
+ const objPrototype = Object.getPrototypeOf(obj)
111
+ if (objPrototype === RegExp.prototype) {
112
+ return 'RegExp'
113
+ }
114
+ if (objPrototype === Date.prototype) {
115
+ return 'Date'
116
+ }
117
+ if (promiseExists && objPrototype === Promise.prototype) {
118
+ return 'Promise'
119
+ }
120
+ if (setExists && objPrototype === Set.prototype) {
121
+ return 'Set'
122
+ }
123
+ if (mapExists && objPrototype === Map.prototype) {
124
+ return 'Map'
125
+ }
126
+ if (weakSetExists && objPrototype === WeakSet.prototype) {
127
+ return 'WeakSet'
128
+ }
129
+ if (weakMapExists && objPrototype === WeakMap.prototype) {
130
+ return 'WeakMap'
131
+ }
132
+ if (dataViewExists && objPrototype === DataView.prototype) {
133
+ return 'DataView'
134
+ }
135
+ if (mapExists && objPrototype === mapIteratorPrototype) {
136
+ return 'Map Iterator'
137
+ }
138
+ if (setExists && objPrototype === setIteratorPrototype) {
139
+ return 'Set Iterator'
140
+ }
141
+ if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
142
+ return 'Array Iterator'
143
+ }
144
+ if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
145
+ return 'String Iterator'
146
+ }
147
+ if (objPrototype === null) {
148
+ return 'Object'
149
+ }
150
+ return Object.prototype.toString
151
+ .call(obj)
152
+ .slice(toStringLeftSliceLength, toStringRightSliceLength)
153
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * from github.com/chaijs/type-detect#4415ced2c49007f097627515806553e7f649c293Z
3
+ * no version indicated in package.json
4
+ * license from this commit is referenced in license.txt
5
+ */
6
+
7
+ const promiseExists = typeof Promise === 'function'
8
+ const globalObject = (Obj => {
9
+ if (typeof globalThis === 'object') {
10
+ return globalThis
11
+ }
12
+ Object.defineProperty(Obj, 'typeDetectGlobalObject', {
13
+ get() {
14
+ return this
15
+ },
16
+ configurable: true,
17
+ })
18
+ // eslint-disable-next-line no-undef
19
+ const global = typeDetectGlobalObject
20
+ delete Obj.typeDetectGlobalObject
21
+ return global
22
+ })(Object.prototype)
23
+ const symbolExists = typeof Symbol !== 'undefined'
24
+ const mapExists = typeof Map !== 'undefined'
25
+ const setExists = typeof Set !== 'undefined'
26
+ const weakMapExists = typeof WeakMap !== 'undefined'
27
+ const weakSetExists = typeof WeakSet !== 'undefined'
28
+ const dataViewExists = typeof DataView !== 'undefined'
29
+ const symbolIteratorExists =
30
+ symbolExists && typeof Symbol.iterator !== 'undefined'
31
+ const symbolToStringTagExists =
32
+ symbolExists && typeof Symbol.toStringTag !== 'undefined'
33
+ const setEntriesExists =
34
+ setExists && typeof Set.prototype.entries === 'function'
35
+ const mapEntriesExists =
36
+ mapExists && typeof Map.prototype.entries === 'function'
37
+ const setIteratorPrototype =
38
+ setEntriesExists && Object.getPrototypeOf(new Set().entries())
39
+ const mapIteratorPrototype =
40
+ mapEntriesExists && Object.getPrototypeOf(new Map().entries())
41
+ const arrayIteratorExists =
42
+ symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function'
43
+ const arrayIteratorPrototype =
44
+ arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]())
45
+ const stringIteratorExists =
46
+ symbolIteratorExists &&
47
+ typeof String.prototype[Symbol.iterator] === 'function'
48
+ const stringIteratorPrototype =
49
+ stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]())
50
+ const toStringLeftSliceLength = 8
51
+ const toStringRightSliceLength = -1
52
+ export default function typeDetect(obj) {
53
+ const typeofObj = typeof obj
54
+ if (typeofObj !== 'object') {
55
+ return typeofObj
56
+ }
57
+ if (obj === null) {
58
+ return 'null'
59
+ }
60
+ if (obj === globalObject) {
61
+ return 'global'
62
+ }
63
+ if (
64
+ Array.isArray(obj) &&
65
+ (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
66
+ ) {
67
+ return 'Array'
68
+ }
69
+ if (typeof window === 'object' && window !== null) {
70
+ if (typeof window.location === 'object' && obj === window.location) {
71
+ return 'Location'
72
+ }
73
+ if (typeof window.document === 'object' && obj === window.document) {
74
+ return 'Document'
75
+ }
76
+ if (typeof window.navigator === 'object') {
77
+ if (
78
+ typeof window.navigator.mimeTypes === 'object' &&
79
+ obj === window.navigator.mimeTypes
80
+ ) {
81
+ return 'MimeTypeArray'
82
+ }
83
+ if (
84
+ typeof window.navigator.plugins === 'object' &&
85
+ obj === window.navigator.plugins
86
+ ) {
87
+ return 'PluginArray'
88
+ }
89
+ }
90
+ if (
91
+ (typeof window.HTMLElement === 'function' ||
92
+ typeof window.HTMLElement === 'object') &&
93
+ obj instanceof window.HTMLElement
94
+ ) {
95
+ if (obj.tagName === 'BLOCKQUOTE') {
96
+ return 'HTMLQuoteElement'
97
+ }
98
+ if (obj.tagName === 'TD') {
99
+ return 'HTMLTableDataCellElement'
100
+ }
101
+ if (obj.tagName === 'TH') {
102
+ return 'HTMLTableHeaderCellElement'
103
+ }
104
+ }
105
+ }
106
+ const stringTag = symbolToStringTagExists && obj[Symbol.toStringTag]
107
+ if (typeof stringTag === 'string') {
108
+ return stringTag
109
+ }
110
+ const objPrototype = Object.getPrototypeOf(obj)
111
+ if (objPrototype === RegExp.prototype) {
112
+ return 'RegExp'
113
+ }
114
+ if (objPrototype === Date.prototype) {
115
+ return 'Date'
116
+ }
117
+ if (promiseExists && objPrototype === Promise.prototype) {
118
+ return 'Promise'
119
+ }
120
+ if (setExists && objPrototype === Set.prototype) {
121
+ return 'Set'
122
+ }
123
+ if (mapExists && objPrototype === Map.prototype) {
124
+ return 'Map'
125
+ }
126
+ if (weakSetExists && objPrototype === WeakSet.prototype) {
127
+ return 'WeakSet'
128
+ }
129
+ if (weakMapExists && objPrototype === WeakMap.prototype) {
130
+ return 'WeakMap'
131
+ }
132
+ if (dataViewExists && objPrototype === DataView.prototype) {
133
+ return 'DataView'
134
+ }
135
+ if (mapExists && objPrototype === mapIteratorPrototype) {
136
+ return 'Map Iterator'
137
+ }
138
+ if (setExists && objPrototype === setIteratorPrototype) {
139
+ return 'Set Iterator'
140
+ }
141
+ if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
142
+ return 'Array Iterator'
143
+ }
144
+ if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
145
+ return 'String Iterator'
146
+ }
147
+ if (objPrototype === null) {
148
+ return 'Object'
149
+ }
150
+ return Object.prototype.toString
151
+ .call(obj)
152
+ .slice(toStringLeftSliceLength, toStringRightSliceLength)
153
+ }
@@ -0,0 +1,18 @@
1
+ // from https://github.com/p2227/universal-eol/blob/25d5629bd5b6e39a1c483e0e1a551513ae80b95c/eol.mjs
2
+ // version 0.0.3
3
+ // modified to work in web-workers
4
+ const runningInWebworker =
5
+ typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope
6
+
7
+ let platform
8
+ if (runningInWebworker) {
9
+ platform = 'webworker'
10
+ } else if (typeof window === 'undefined') {
11
+ platform = process.platform
12
+ } else {
13
+ platform = navigator.platform
14
+ }
15
+
16
+ const EOL = /win/i.test(platform) ? '\r\n' : '\n'
17
+
18
+ module.exports = EOL
@@ -0,0 +1,18 @@
1
+ // from https://github.com/p2227/universal-eol/blob/25d5629bd5b6e39a1c483e0e1a551513ae80b95c/eol.mjs
2
+ // version 0.0.3
3
+ // modified to work in web-workers
4
+ const runningInWebworker =
5
+ typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope
6
+
7
+ let platform
8
+ if (runningInWebworker) {
9
+ platform = 'webworker'
10
+ } else if (typeof window === 'undefined') {
11
+ platform = process.platform
12
+ } else {
13
+ platform = navigator.platform
14
+ }
15
+
16
+ const EOL = /win/i.test(platform) ? '\r\n' : '\n'
17
+
18
+ export default EOL
@@ -0,0 +1,10 @@
1
+ /**
2
+ * this utility expects strOrNum to have already been asserted to be a string
3
+ * or number
4
+ */
5
+
6
+ const ensureNumber = strOrNum => {
7
+ return typeof strOrNum === 'number' ? strOrNum : Number(strOrNum)
8
+ }
9
+
10
+ module.exports = ensureNumber
@@ -0,0 +1,2 @@
1
+ import { default as ensureNumber } from '@common-fp/shared-internals-types/ensure-number'
2
+ export = ensureNumber
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/ensure-number'
@@ -0,0 +1,10 @@
1
+ /**
2
+ * this utility expects strOrNum to have already been asserted to be a string
3
+ * or number
4
+ */
5
+
6
+ const ensureNumber = strOrNum => {
7
+ return typeof strOrNum === 'number' ? strOrNum : Number(strOrNum)
8
+ }
9
+
10
+ export default ensureNumber
@@ -0,0 +1,12 @@
1
+ /**
2
+ * this utility expects arrOrSet to have already been asserted to be an array
3
+ * or set
4
+ */
5
+
6
+ const getType = require('./get-type.cjs')
7
+
8
+ const ensureSet = arrOrSet => {
9
+ return getType(arrOrSet) === 'set' ? arrOrSet : new Set(arrOrSet)
10
+ }
11
+
12
+ module.exports = ensureSet
@@ -0,0 +1,2 @@
1
+ import { default as ensureSet } from '@common-fp/shared-internals-types/ensure-set'
2
+ export = ensureSet
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/ensure-set'
@@ -0,0 +1,12 @@
1
+ /**
2
+ * this utility expects arrOrSet to have already been asserted to be an array
3
+ * or set
4
+ */
5
+
6
+ import getType from './get-type.mjs'
7
+
8
+ const ensureSet = arrOrSet => {
9
+ return getType(arrOrSet) === 'set' ? arrOrSet : new Set(arrOrSet)
10
+ }
11
+
12
+ export default ensureSet
package/dist/eol.cjs ADDED
@@ -0,0 +1,3 @@
1
+ const EOL = require('./deps/universal-eol.cjs')
2
+
3
+ module.exports = EOL
package/dist/eol.d.cts ADDED
@@ -0,0 +1,2 @@
1
+ import { default as eol } from '@common-fp/shared-internals-types/eol'
2
+ export = eol
package/dist/eol.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/eol'
package/dist/eol.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import EOL from './deps/universal-eol.mjs'
2
+
3
+ export default EOL
@@ -0,0 +1,9 @@
1
+ const assertArgTypeIsOneOf = require('./assert-arg-type-is-one-of.cjs')
2
+
3
+ const getFnByType = (typeToFn, argType, argName, utilName) => {
4
+ const supportedTypes = Object.keys(typeToFn)
5
+ assertArgTypeIsOneOf(argType, argName, supportedTypes, utilName)
6
+ return typeToFn[argType]
7
+ }
8
+
9
+ module.exports = getFnByType
@@ -0,0 +1,2 @@
1
+ import { default as getFnByType } from '@common-fp/shared-internals-types/get-fn-by-type'
2
+ export = getFnByType
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/get-fn-by-type'
@@ -0,0 +1,9 @@
1
+ import assertArgTypeIsOneOf from './assert-arg-type-is-one-of.mjs'
2
+
3
+ const getFnByType = (typeToFn, argType, argName, utilName) => {
4
+ const supportedTypes = Object.keys(typeToFn)
5
+ assertArgTypeIsOneOf(argType, argName, supportedTypes, utilName)
6
+ return typeToFn[argType]
7
+ }
8
+
9
+ export default getFnByType
@@ -0,0 +1,11 @@
1
+ const assertArgTypeIsOneOf = require('./assert-arg-type-is-one-of.cjs')
2
+ const getType = require('./get-type.cjs')
3
+
4
+ const getFn = (typeToFn, arg, argName, utilName) => {
5
+ const supportedTypes = Object.keys(typeToFn)
6
+ const argType = getType(arg)
7
+ assertArgTypeIsOneOf(argType, argName, supportedTypes, utilName)
8
+ return typeToFn[argType]
9
+ }
10
+
11
+ module.exports = getFn
@@ -0,0 +1,2 @@
1
+ import { default as getFn } from '@common-fp/shared-internals-types/get-fn'
2
+ export = getFn
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/get-fn'
@@ -0,0 +1,11 @@
1
+ import assertArgTypeIsOneOf from './assert-arg-type-is-one-of.mjs'
2
+ import getType from './get-type.mjs'
3
+
4
+ const getFn = (typeToFn, arg, argName, utilName) => {
5
+ const supportedTypes = Object.keys(typeToFn)
6
+ const argType = getType(arg)
7
+ assertArgTypeIsOneOf(argType, argName, supportedTypes, utilName)
8
+ return typeToFn[argType]
9
+ }
10
+
11
+ export default getFn
@@ -0,0 +1,23 @@
1
+ /**
2
+ * this utility expects the passed collection to have already been asserted
3
+ * also, the iteratorType error shouldn't ever reach users of Common FP, it's
4
+ * just here in case custom utility authors mess up.
5
+ */
6
+
7
+ const getType = require('./get-type.cjs')
8
+
9
+ const getIterator = (iteratorType, coll, collType) => {
10
+ validateIteratorType(iteratorType)
11
+ const type = collType || getType(coll)
12
+ return type === 'object' ?
13
+ Object[iteratorType](coll).values()
14
+ : coll[iteratorType]()
15
+ }
16
+
17
+ function validateIteratorType(iteratorType) {
18
+ if (!['values', 'keys', 'entries'].includes(iteratorType)) {
19
+ throw new Error("iteratorType must be one of 'values', 'keys' or 'entries'")
20
+ }
21
+ }
22
+
23
+ module.exports = getIterator
@@ -0,0 +1,2 @@
1
+ import { default as getIterator } from '@common-fp/shared-internals-types/get-iterator'
2
+ export = getIterator
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/get-iterator'
@@ -0,0 +1,23 @@
1
+ /**
2
+ * this utility expects the passed collection to have already been asserted
3
+ * also, the iteratorType error shouldn't ever reach users of Common FP, it's
4
+ * just here in case custom utility authors mess up.
5
+ */
6
+
7
+ import getType from './get-type.mjs'
8
+
9
+ const getIterator = (iteratorType, coll, collType) => {
10
+ validateIteratorType(iteratorType)
11
+ const type = collType || getType(coll)
12
+ return type === 'object' ?
13
+ Object[iteratorType](coll).values()
14
+ : coll[iteratorType]()
15
+ }
16
+
17
+ function validateIteratorType(iteratorType) {
18
+ if (!['values', 'keys', 'entries'].includes(iteratorType)) {
19
+ throw new Error("iteratorType must be one of 'values', 'keys' or 'entries'")
20
+ }
21
+ }
22
+
23
+ export default getIterator
@@ -0,0 +1,5 @@
1
+ const getRandomInt = (min, max) => {
2
+ return Math.floor(Math.random() * (max - min + 1)) + min
3
+ }
4
+
5
+ module.exports = getRandomInt
@@ -0,0 +1,2 @@
1
+ import { default as getRandomInt } from '@common-fp/shared-internals-types/get-random-int'
2
+ export = getRandomInt
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/get-random-int'
@@ -0,0 +1,5 @@
1
+ const getRandomInt = (min, max) => {
2
+ return Math.floor(Math.random() * (max - min + 1)) + min
3
+ }
4
+
5
+ export default getRandomInt
@@ -0,0 +1,5 @@
1
+ const typeDetect = require('./deps/type-detect.cjs')
2
+
3
+ const getType = anything => typeDetect(anything).toLowerCase()
4
+
5
+ module.exports = getType
@@ -0,0 +1,2 @@
1
+ import { default as getType } from '@common-fp/shared-internals-types/get-type'
2
+ export = getType
@@ -0,0 +1 @@
1
+ export { default } from '@common-fp/shared-internals-types/get-type'
@@ -0,0 +1,5 @@
1
+ import typeDetect from './deps/type-detect.mjs'
2
+
3
+ const getType = anything => typeDetect(anything).toLowerCase()
4
+
5
+ export default getType
package/dist/index.cjs ADDED
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ aOrAn: require('./a-or-an.cjs'),
3
+ assertArgHasValuesOfType: require('./assert-arg-has-values-of-type.cjs'),
4
+ assertArgIsArrayOfAcceptedTypes: require('./assert-arg-is-array-of-accepted-types.cjs'),
5
+ assertArgIsArrayOfSameType: require('./assert-arg-is-array-of-same-type.cjs'),
6
+ assertArgIsArrayOfType: require('./assert-arg-is-array-of-type.cjs'),
7
+ assertArgIsChar: require('./assert-arg-is-char.cjs'),
8
+ assertArgIsInt: require('./assert-arg-is-int.cjs'),
9
+ assertArgIsOneOfType: require('./assert-arg-is-one-of-type.cjs'),
10
+ assertArgIsType: require('./assert-arg-is-type.cjs'),
11
+ assertArgSharesTypeWith: require('./assert-arg-shares-type-with.cjs'),
12
+ assertArgTypeIsOneOf: require('./assert-arg-type-is-one-of.cjs'),
13
+ containsType: require('./contains-type.cjs'),
14
+ ensureNumber: require('./ensure-number.cjs'),
15
+ ensureSet: require('./ensure-set.cjs'),
16
+ eol: require('./eol.cjs'),
17
+ getFn: require('./get-fn.cjs'),
18
+ getFnByType: require('./get-fn-by-type.cjs'),
19
+ getIterator: require('./get-iterator.cjs'),
20
+ getRandomInt: require('./get-random-int.cjs'),
21
+ getType: require('./get-type.cjs'),
22
+ negate: require('./negate.cjs'),
23
+ toEnglishList: require('./to-english-list.cjs'),
24
+ truncateToNChars: require('./truncate-to-n-chars.cjs'),
25
+ validateArrayKeys: require('./validate-array-keys.cjs'),
26
+ validateIsBetweenInput: require('./validate-is-between-input.cjs'),
27
+ validateObjectKeys: require('./validate-object-keys.cjs'),
28
+ validateRange: require('./validate-range.cjs'),
29
+ commonTypes: require('./common-types.cjs'),
30
+ }
@@ -0,0 +1,2 @@
1
+ import * as sharedInternals from '@common-fp/shared-internals-types'
2
+ export = sharedInternals
@@ -0,0 +1 @@
1
+ export * from '@common-fp/shared-internals-types'