@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.
- package/dist/a-or-an.cjs +6 -0
- package/dist/a-or-an.d.cts +2 -0
- package/dist/a-or-an.d.ts +1 -0
- package/dist/a-or-an.mjs +6 -0
- package/dist/assert-arg-has-values-of-type.cjs +29 -0
- package/dist/assert-arg-has-values-of-type.d.cts +2 -0
- package/dist/assert-arg-has-values-of-type.d.ts +1 -0
- package/dist/assert-arg-has-values-of-type.mjs +29 -0
- package/dist/assert-arg-is-array-of-accepted-types.cjs +28 -0
- package/dist/assert-arg-is-array-of-accepted-types.d.cts +2 -0
- package/dist/assert-arg-is-array-of-accepted-types.d.ts +1 -0
- package/dist/assert-arg-is-array-of-accepted-types.mjs +28 -0
- package/dist/assert-arg-is-array-of-same-type.cjs +34 -0
- package/dist/assert-arg-is-array-of-same-type.d.cts +2 -0
- package/dist/assert-arg-is-array-of-same-type.d.ts +1 -0
- package/dist/assert-arg-is-array-of-same-type.mjs +34 -0
- package/dist/assert-arg-is-array-of-type.cjs +18 -0
- package/dist/assert-arg-is-array-of-type.d.cts +2 -0
- package/dist/assert-arg-is-array-of-type.d.ts +1 -0
- package/dist/assert-arg-is-array-of-type.mjs +18 -0
- package/dist/assert-arg-is-char.cjs +19 -0
- package/dist/assert-arg-is-char.d.cts +2 -0
- package/dist/assert-arg-is-char.d.ts +1 -0
- package/dist/assert-arg-is-char.mjs +19 -0
- package/dist/assert-arg-is-int.cjs +35 -0
- package/dist/assert-arg-is-int.d.cts +2 -0
- package/dist/assert-arg-is-int.d.ts +1 -0
- package/dist/assert-arg-is-int.mjs +35 -0
- package/dist/assert-arg-is-one-of-type.cjs +17 -0
- package/dist/assert-arg-is-one-of-type.d.cts +2 -0
- package/dist/assert-arg-is-one-of-type.d.ts +1 -0
- package/dist/assert-arg-is-one-of-type.mjs +17 -0
- package/dist/assert-arg-is-type.cjs +12 -0
- package/dist/assert-arg-is-type.d.cts +2 -0
- package/dist/assert-arg-is-type.d.ts +1 -0
- package/dist/assert-arg-is-type.mjs +12 -0
- package/dist/assert-arg-shares-type-with.cjs +12 -0
- package/dist/assert-arg-shares-type-with.d.cts +2 -0
- package/dist/assert-arg-shares-type-with.d.ts +1 -0
- package/dist/assert-arg-shares-type-with.mjs +12 -0
- package/dist/assert-arg-type-is-one-of.cjs +14 -0
- package/dist/assert-arg-type-is-one-of.d.cts +2 -0
- package/dist/assert-arg-type-is-one-of.d.ts +1 -0
- package/dist/assert-arg-type-is-one-of.mjs +14 -0
- package/dist/common-types.cjs +39 -0
- package/dist/common-types.d.cts +2 -0
- package/dist/common-types.d.ts +1 -0
- package/dist/common-types.mjs +39 -0
- package/dist/contains-type.cjs +9 -0
- package/dist/contains-type.d.cts +2 -0
- package/dist/contains-type.d.ts +1 -0
- package/dist/contains-type.mjs +9 -0
- package/dist/deps/type-detect.cjs +153 -0
- package/dist/deps/type-detect.mjs +153 -0
- package/dist/deps/universal-eol.cjs +18 -0
- package/dist/deps/universal-eol.mjs +18 -0
- package/dist/ensure-number.cjs +10 -0
- package/dist/ensure-number.d.cts +2 -0
- package/dist/ensure-number.d.ts +1 -0
- package/dist/ensure-number.mjs +10 -0
- package/dist/ensure-set.cjs +12 -0
- package/dist/ensure-set.d.cts +2 -0
- package/dist/ensure-set.d.ts +1 -0
- package/dist/ensure-set.mjs +12 -0
- package/dist/eol.cjs +3 -0
- package/dist/eol.d.cts +2 -0
- package/dist/eol.d.ts +1 -0
- package/dist/eol.mjs +3 -0
- package/dist/get-fn-by-type.cjs +9 -0
- package/dist/get-fn-by-type.d.cts +2 -0
- package/dist/get-fn-by-type.d.ts +1 -0
- package/dist/get-fn-by-type.mjs +9 -0
- package/dist/get-fn.cjs +11 -0
- package/dist/get-fn.d.cts +2 -0
- package/dist/get-fn.d.ts +1 -0
- package/dist/get-fn.mjs +11 -0
- package/dist/get-iterator.cjs +23 -0
- package/dist/get-iterator.d.cts +2 -0
- package/dist/get-iterator.d.ts +1 -0
- package/dist/get-iterator.mjs +23 -0
- package/dist/get-random-int.cjs +5 -0
- package/dist/get-random-int.d.cts +2 -0
- package/dist/get-random-int.d.ts +1 -0
- package/dist/get-random-int.mjs +5 -0
- package/dist/get-type.cjs +5 -0
- package/dist/get-type.d.cts +2 -0
- package/dist/get-type.d.ts +1 -0
- package/dist/get-type.mjs +5 -0
- package/dist/index.cjs +30 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +28 -0
- package/dist/negate.cjs +6 -0
- package/dist/negate.d.cts +2 -0
- package/dist/negate.d.ts +1 -0
- package/dist/negate.mjs +6 -0
- package/dist/to-english-list.cjs +12 -0
- package/dist/to-english-list.d.cts +2 -0
- package/dist/to-english-list.d.ts +1 -0
- package/dist/to-english-list.mjs +12 -0
- package/dist/truncate-to-n-chars.cjs +18 -0
- package/dist/truncate-to-n-chars.d.cts +2 -0
- package/dist/truncate-to-n-chars.d.ts +1 -0
- package/dist/truncate-to-n-chars.mjs +18 -0
- package/dist/validate-array-keys.cjs +19 -0
- package/dist/validate-array-keys.d.cts +2 -0
- package/dist/validate-array-keys.d.ts +1 -0
- package/dist/validate-array-keys.mjs +19 -0
- package/dist/validate-is-between-input.cjs +20 -0
- package/dist/validate-is-between-input.d.cts +2 -0
- package/dist/validate-is-between-input.d.ts +1 -0
- package/dist/validate-is-between-input.mjs +20 -0
- package/dist/validate-object-keys.cjs +13 -0
- package/dist/validate-object-keys.d.cts +2 -0
- package/dist/validate-object-keys.d.ts +1 -0
- package/dist/validate-object-keys.mjs +13 -0
- package/dist/validate-range.cjs +14 -0
- package/dist/validate-range.d.cts +2 -0
- package/dist/validate-range.d.ts +1 -0
- package/dist/validate-range.mjs +14 -0
- package/license.txt +106 -0
- package/package.json +39 -0
- 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 @@
|
|
|
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 @@
|
|
|
1
|
+
export { default } from '@common-fp/shared-internals-types/ensure-number'
|
|
@@ -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 @@
|
|
|
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
package/dist/eol.d.cts
ADDED
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,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 @@
|
|
|
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
|
package/dist/get-fn.cjs
ADDED
|
@@ -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
|
package/dist/get-fn.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@common-fp/shared-internals-types/get-fn'
|
package/dist/get-fn.mjs
ADDED
|
@@ -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 @@
|
|
|
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 @@
|
|
|
1
|
+
export { default } from '@common-fp/shared-internals-types/get-random-int'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@common-fp/shared-internals-types/get-type'
|
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
|
+
}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@common-fp/shared-internals-types'
|