foxts 1.0.4 → 1.0.6

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.
@@ -1 +1 @@
1
- "use strict";var e=require("../identity/index.cjs");function t(r,n,i=e.identity){let u;const s=n.values();for(;!(u=s.next()).done;)r.push(i(u.value));return r}exports.appendSetElementsToArray=function(r,n,i=e.identity){if(!Array.isArray(n))return t(r,n,i);for(let e=0,u=n.length;e<u;e++)t(r,n[e],i);return r};
1
+ "use strict";var e=require("../identity/index.cjs");function r(e,r,t){let n;const i=r.values();for(;!(n=i.next()).done;)e.push(t(n.value));return e}exports.appendSetElementsToArray=function(t,n,i=e.identity){if(!Array.isArray(n))return r(t,n,i);for(let e=0,u=n.length;e<u;e++)r(t,n[e],i);return t};
@@ -1 +1 @@
1
- import{identity as e}from"../identity/index.mjs";function r(t,n,o=e){let i;const u=n.values();for(;!(i=u.next()).done;)t.push(o(i.value));return t}function t(n,o,i=e){if(!Array.isArray(o))return r(n,o,i);for(let e=0,t=o.length;e<t;e++)r(n,o[e],i);return n}export{t as appendSetElementsToArray};
1
+ import{identity as e}from"../identity/index.mjs";function r(e,r,t){let n;const o=r.values();for(;!(n=o.next()).done;)e.push(t(n.value));return e}function t(n,o,i=e){if(!Array.isArray(o))return r(n,o,i);for(let e=0,t=o.length;e<t;e++)r(n,o[e],i);return n}export{t as appendSetElementsToArray};
package/bitwise/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const t=t=>t>>16&65535,r=t=>65535&t,e=t=>t>>20&1023,s=t=>t>>10&1023,n=t=>1023&t;exports.bitCount=function(t){return t-=t>>1&0x55555555,((t=(0x33333333&t)+(t>>2&0x33333333))+(t>>4)&0xf0f0f0f)*0x1010101>>24},exports.deleteBit=function(t,r){return t&~r},exports.getBit=function(t,r){return!!(t&r)},exports.packThreeBits=(t,r,e)=>t<<20|r<<10|e,exports.packTwoBits=(t,r)=>t<<16|r,exports.setBit=function(t,r){return t|r},exports.unpackThreeBits=function(t,r=Array.from([,,,].keys())){return r[0]=e(t),r[1]=s(t),r[2]=n(t),r},exports.unpackThreeBitsFirst=e,exports.unpackThreeBitsSecond=s,exports.unpackThreeBitsThird=n,exports.unpackTwoBits=function(e,s=Array.from([,,].keys())){return s[0]=t(e),s[1]=r(e),s},exports.unpackTwoBitsFirst=t,exports.unpackTwoBitsSecond=r;
1
+ "use strict";const t=t=>t>>16&65535,e=t=>65535&t,r=t=>t>>20&1023,s=t=>t>>10&1023,o=t=>1023&t;exports.bitCount=function(t){return t-=t>>1&0x55555555,((t=(0x33333333&t)+(t>>2&0x33333333))+(t>>4)&0xf0f0f0f)*0x1010101>>24},exports.deleteBit=(t,e)=>t&~e,exports.getBit=(t,e)=>!!(t&e),exports.missingBit=(t,e)=>!(t&e),exports.packThreeBits=(t,e,r)=>t<<20|e<<10|r,exports.packTwoBits=(t,e)=>t<<16|e,exports.setBit=(t,e)=>t|e,exports.unpackThreeBits=function(t,e=Array.from([,,,].keys())){return e[0]=r(t),e[1]=s(t),e[2]=o(t),e},exports.unpackThreeBitsFirst=r,exports.unpackThreeBitsSecond=s,exports.unpackThreeBitsThird=o,exports.unpackTwoBits=function(r,s=Array.from([,,].keys())){return s[0]=t(r),s[1]=e(r),s},exports.unpackTwoBitsFirst=t,exports.unpackTwoBitsSecond=e;
@@ -1,7 +1,8 @@
1
1
  declare function bitCount(n: number): number;
2
- declare function getBit(n: number, mask: number): boolean;
3
- declare function setBit(n: number, mask: number): number;
4
- declare function deleteBit(n: number, mask: number): number;
2
+ declare const getBit: (n: number, mask: number) => boolean;
3
+ declare const missingBit: (n: number, mask: number) => boolean;
4
+ declare const setBit: (n: number, mask: number) => number;
5
+ declare const deleteBit: (n: number, mask: number) => number;
5
6
  /** Packs two 16-bit integers (0~65535) into one 32-bit integer */
6
7
  declare const packTwoBits: (a: number, b: number) => number;
7
8
  declare const unpackTwoBitsFirst: (value: number) => number;
@@ -26,4 +27,4 @@ declare const unpackThreeBitsThird: (value: number) => number;
26
27
  */
27
28
  declare function unpackThreeBits(value: number, arr?: [a: number, b: number, c: number]): [a: number, b: number, c: number];
28
29
 
29
- export { bitCount, deleteBit, getBit, packThreeBits, packTwoBits, setBit, unpackThreeBits, unpackThreeBitsFirst, unpackThreeBitsSecond, unpackThreeBitsThird, unpackTwoBits, unpackTwoBitsFirst, unpackTwoBitsSecond };
30
+ export { bitCount, deleteBit, getBit, missingBit, packThreeBits, packTwoBits, setBit, unpackThreeBits, unpackThreeBitsFirst, unpackThreeBitsSecond, unpackThreeBitsThird, unpackTwoBits, unpackTwoBitsFirst, unpackTwoBitsSecond };
package/bitwise/index.mjs CHANGED
@@ -1 +1 @@
1
- function t(t){return t-=t>>1&0x55555555,((t=(0x33333333&t)+(t>>2&0x33333333))+(t>>4)&0xf0f0f0f)*0x1010101>>24}function n(t,n){return!!(t&n)}function r(t,n){return t|n}function e(t,n){return t&~n}const i=(t,n)=>t<<16|n,u=t=>t>>16&65535,c=t=>65535&t;function o(t,n=Array.from([,,].keys())){return n[0]=u(t),n[1]=c(t),n}const s=(t,n,r)=>t<<20|n<<10|r,f=t=>t>>20&1023,B=t=>t>>10&1023,a=t=>1023&t;function k(t,n=Array.from([,,,].keys())){return n[0]=f(t),n[1]=B(t),n[2]=a(t),n}export{t as bitCount,e as deleteBit,n as getBit,s as packThreeBits,i as packTwoBits,r as setBit,k as unpackThreeBits,f as unpackThreeBitsFirst,B as unpackThreeBitsSecond,a as unpackThreeBitsThird,o as unpackTwoBits,u as unpackTwoBitsFirst,c as unpackTwoBitsSecond};
1
+ function t(t){return t-=t>>1&0x55555555,((t=(0x33333333&t)+(t>>2&0x33333333))+(t>>4)&0xf0f0f0f)*0x1010101>>24}const e=(t,e)=>!!(t&e),i=(t,e)=>!(t&e),n=(t,e)=>t|e,r=(t,e)=>t&~e,s=(t,e)=>t<<16|e,c=t=>t>>16&65535,o=t=>65535&t;function u(t,e=Array.from([,,].keys())){return e[0]=c(t),e[1]=o(t),e}const B=(t,e,i)=>t<<20|e<<10|i,a=t=>t>>20&1023,k=t=>t>>10&1023,p=t=>1023&t;function T(t,e=Array.from([,,,].keys())){return e[0]=a(t),e[1]=k(t),e[2]=p(t),e}export{t as bitCount,r as deleteBit,e as getBit,i as missingBit,B as packThreeBits,s as packTwoBits,n as setBit,T as unpackThreeBits,a as unpackThreeBitsFirst,k as unpackThreeBitsSecond,p as unpackThreeBitsThird,u as unpackTwoBits,c as unpackTwoBitsFirst,o as unpackTwoBitsSecond};
package/guard/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";function s(s){switch(s){case null:return s=>null!==s;case void 0:return s=>void 0!==s;case!1:return s=>!1!==s;case"nullish":return s=>null!=s;case"falsy":return s=>!!s;default:throw TypeError("Invalid argument")}}const r=s("falsy"),l=s(null),t=s("nullish");exports.isFalsy=s=>!s,exports.isNonNull=l,exports.isNonNullish=t,exports.isTruthy=r,exports.not=s;
1
+ "use strict";function r(r){switch(r){case null:return r=>null!==r;case void 0:return r=>void 0!==r;case!1:return r=>!1!==r;case"nullish":return r=>null!=r;case"falsy":return r=>!!r;default:throw TypeError("Invalid argument")}}function n(r){switch(r){case null:return r=>null===r;case void 0:return r=>void 0===r;case!1:return r=>!1===r;case"nullish":return r=>null==r;case"falsy":return r=>!r;case"truthy":return r=>!!r;default:throw TypeError("Invalid argument")}}const t=n("truthy"),e=n("falsy"),u=r(null),l=r("nullish");exports.invariant=function(r,n='[foxts/invariant] "value" is null or undefined'){if(null==r)throw TypeError(n)},exports.is=n,exports.isFalsy=e,exports.isNonNull=u,exports.isNonNullish=l,exports.isTruthy=t,exports.not=r,exports.nullthrow=function(r,n='[foxts/invariant] "value" is null or undefined'){if(null==r)throw TypeError(n);return r};
package/guard/index.d.ts CHANGED
@@ -3,9 +3,17 @@ declare function not(arg: undefined): <T>(i: T | undefined) => i is T;
3
3
  declare function not(arg: false): <T>(i: T | false) => i is T;
4
4
  declare function not(arg: 'nullish'): <T>(i: T | null | undefined) => i is T;
5
5
  declare function not(arg: 'falsy'): <T>(i: T | 0 | '' | false | null | undefined) => i is T;
6
+ declare function is(arg: null): (i: unknown) => i is null;
7
+ declare function is(arg: undefined): (i: unknown) => i is undefined;
8
+ declare function is(arg: false): (i: unknown) => i is false;
9
+ declare function is(arg: 'nullish'): (i: unknown) => i is null | undefined;
10
+ declare function is(arg: 'falsy'): (i: unknown) => i is 0 | '' | false | null | undefined;
11
+ declare function is(arg: 'truthy'): <T>(i: T | 0 | '' | false | null | undefined) => i is T;
6
12
  declare const isTruthy: <T>(i: T | 0 | "" | false | null | undefined) => i is T;
7
- declare const isFalsy: <T>(i: T | 0 | "" | false | null | undefined) => i is 0 | "" | false | null | undefined;
13
+ declare const isFalsy: (i: unknown) => i is 0 | "" | false | null | undefined;
8
14
  declare const isNonNull: <T>(i: T | null) => i is T;
9
15
  declare const isNonNullish: <T>(i: T | null | undefined) => i is T;
16
+ declare function nullthrow<T>(value: T | null | undefined, message?: string): T;
17
+ declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
10
18
 
11
- export { isFalsy, isNonNull, isNonNullish, isTruthy, not };
19
+ export { invariant, is, isFalsy, isNonNull, isNonNullish, isTruthy, not, nullthrow };
package/guard/index.mjs CHANGED
@@ -1 +1 @@
1
- function l(l){switch(l){case null:return l=>null!==l;case void 0:return l=>void 0!==l;case!1:return l=>!1!==l;case"nullish":return l=>null!=l;case"falsy":return l=>!!l;default:throw TypeError("Invalid argument")}}const n=l("falsy"),r=l=>!l,s=l(null),u=l("nullish");export{r as isFalsy,s as isNonNull,u as isNonNullish,n as isTruthy,l as not};
1
+ function n(n){switch(n){case null:return n=>null!==n;case void 0:return n=>void 0!==n;case!1:return n=>!1!==n;case"nullish":return n=>null!=n;case"falsy":return n=>!!n;default:throw TypeError("Invalid argument")}}function r(n){switch(n){case null:return n=>null===n;case void 0:return n=>void 0===n;case!1:return n=>!1===n;case"nullish":return n=>null==n;case"falsy":return n=>!n;case"truthy":return n=>!!n;default:throw TypeError("Invalid argument")}}const l=r("truthy"),u=r("falsy"),t=n(null),e=n("nullish");function i(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r);return n}function s(n,r='[foxts/invariant] "value" is null or undefined'){if(null==n)throw TypeError(r)}export{s as invariant,r as is,u as isFalsy,t as isNonNull,e as isNonNullish,l as isTruthy,n as not,i as nullthrow};
@@ -0,0 +1 @@
1
+ "use strict";exports.isProbablyIpv4=function(t){if(t.length<7||t.length>15)return!1;let e=0;for(let r=0;r<t.length;r+=1){const n=t.charCodeAt(r);if(46===n)e+=1;else if(n<48||n>57)return!1}return 3===e&&46!==t.charCodeAt(0)&&46!==t.charCodeAt(t.length-1)},exports.isProbablyIpv6=function(t){if(t.length<3)return!1;let e="["===t[0]?1:0,r=t.length;if("]"===t[r-1]&&(r-=1),r-e>39)return!1;let n=!1;for(;e<r;e+=1){const r=t.charCodeAt(e);if(58===r)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=90))return!1}return n};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check if a hostname is an IP. You should be aware that this only works
3
+ * because `hostname` is already garanteed to be a valid hostname!
4
+ */
5
+ declare function isProbablyIpv4(hostname: string): boolean;
6
+ declare function isProbablyIpv6(hostname: string): boolean;
7
+
8
+ export { isProbablyIpv4, isProbablyIpv6 };
@@ -0,0 +1 @@
1
+ function e(e){if(e.length<7||e.length>15)return!1;let t=0;for(let r=0;r<e.length;r+=1){const n=e.charCodeAt(r);if(46===n)t+=1;else if(n<48||n>57)return!1}return 3===t&&46!==e.charCodeAt(0)&&46!==e.charCodeAt(e.length-1)}function t(e){if(e.length<3)return!1;let t="["===e[0]?1:0,r=e.length;if("]"===e[r-1]&&(r-=1),r-t>39)return!1;let n=!1;for(;t<r;t+=1){const r=e.charCodeAt(t);if(58===r)n=!0;else if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=90))return!1}return n}export{e as isProbablyIpv4,t as isProbablyIpv6};
package/noop/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";exports.falseFn=()=>!1,exports.noop=()=>{},exports.throwFn=()=>{throw Error()},exports.trueFn=()=>!0;
@@ -0,0 +1,9 @@
1
+ interface Noop<T = any> {
2
+ (...args: any[]): T;
3
+ }
4
+ declare const noop: Noop;
5
+ declare const trueFn: Noop<true>;
6
+ declare const falseFn: Noop<false>;
7
+ declare const throwFn: Noop<never>;
8
+
9
+ export { falseFn, noop, throwFn, trueFn };
package/noop/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const o=()=>{},r=()=>!0,n=()=>!1,t=()=>{throw Error()};export{n as falseFn,o as noop,t as throwFn,r as trueFn};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxts",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Opinionated collection of common TypeScript utils by @SukkaW",
5
5
  "repository": {
6
6
  "url": "https://github.com/SukkaW/foxts"
@@ -38,15 +38,6 @@
38
38
  "require": "./append-set-elements-to-array/index.cjs",
39
39
  "default": "./append-set-elements-to-array/index.cjs"
40
40
  },
41
- "./bitwise": {
42
- "types": "./bitwise/index.d.ts",
43
- "import": {
44
- "types": "./bitwise/index.d.ts",
45
- "default": "./bitwise/index.mjs"
46
- },
47
- "require": "./bitwise/index.cjs",
48
- "default": "./bitwise/index.cjs"
49
- },
50
41
  "./async-write-to-stream": {
51
42
  "types": "./async-write-to-stream/index.d.ts",
52
43
  "import": {
@@ -74,6 +65,15 @@
74
65
  "require": "./fnv1a/index.cjs",
75
66
  "default": "./fnv1a/index.cjs"
76
67
  },
68
+ "./bitwise": {
69
+ "types": "./bitwise/index.d.ts",
70
+ "import": {
71
+ "types": "./bitwise/index.d.ts",
72
+ "default": "./bitwise/index.mjs"
73
+ },
74
+ "require": "./bitwise/index.cjs",
75
+ "default": "./bitwise/index.cjs"
76
+ },
77
77
  "./fnv1a52": {
78
78
  "types": "./fnv1a52/index.d.ts",
79
79
  "import": {
@@ -110,6 +110,15 @@
110
110
  "require": "./identity/index.cjs",
111
111
  "default": "./identity/index.cjs"
112
112
  },
113
+ "./is-probably-ip": {
114
+ "types": "./is-probably-ip/index.d.ts",
115
+ "import": {
116
+ "types": "./is-probably-ip/index.d.ts",
117
+ "default": "./is-probably-ip/index.mjs"
118
+ },
119
+ "require": "./is-probably-ip/index.cjs",
120
+ "default": "./is-probably-ip/index.cjs"
121
+ },
113
122
  "./merge-headers": {
114
123
  "types": "./merge-headers/index.d.ts",
115
124
  "import": {
@@ -119,6 +128,15 @@
119
128
  "require": "./merge-headers/index.cjs",
120
129
  "default": "./merge-headers/index.cjs"
121
130
  },
131
+ "./noop": {
132
+ "types": "./noop/index.d.ts",
133
+ "import": {
134
+ "types": "./noop/index.d.ts",
135
+ "default": "./noop/index.mjs"
136
+ },
137
+ "require": "./noop/index.cjs",
138
+ "default": "./noop/index.cjs"
139
+ },
122
140
  "./simple-string-hash": {
123
141
  "types": "./simple-string-hash/index.d.ts",
124
142
  "import": {