solid-new-bucket 0.0.1 → 0.0.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.
- package/dist/index.d.mts +142 -0
- package/dist/index.d.ts +142 -0
- package/dist/index.js +371 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +323 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -2
- package/app/index.tsx +0 -12
- package/index.html +0 -16
- package/src/arrayHelpers.ts +0 -48
- package/src/buckets.ts +0 -182
- package/src/checks.ts +0 -57
- package/src/conditionals.ts +0 -35
- package/src/converters.ts +0 -27
- package/src/functions.d.ts +0 -23
- package/src/generators.ts +0 -24
- package/src/global.d.ts +0 -30
- package/src/index.ts +0 -14
- package/src/others.ts +0 -28
- package/src/wrappers.ts +0 -28
- package/tsconfig.json +0 -17
- package/vite.config.ts +0 -20
package/src/checks.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Check if array or string is not empty.
|
|
4
|
-
* @param v array of any, string or undefined
|
|
5
|
-
* @returns true if target is not empty
|
|
6
|
-
*/
|
|
7
|
-
export function isNotEmpty<T>(v?: T[]): boolean
|
|
8
|
-
export function isNotEmpty(v?: string): boolean
|
|
9
|
-
export function isNotEmpty(v: any) {
|
|
10
|
-
if (!v) return false
|
|
11
|
-
if (typeof(v) === "string") {
|
|
12
|
-
return v.length > 0
|
|
13
|
-
}
|
|
14
|
-
if (typeof(v) === "object") {
|
|
15
|
-
if (Array.isArray(v)) {
|
|
16
|
-
return v.length > 0
|
|
17
|
-
}
|
|
18
|
-
return Object.keys(v).length > 0
|
|
19
|
-
}
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Check if value is number.
|
|
25
|
-
* @param v any
|
|
26
|
-
* @returns true if value is number
|
|
27
|
-
*/
|
|
28
|
-
export function isNumber(v: any) {
|
|
29
|
-
return typeof(v) === "number";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Compare two date string.
|
|
34
|
-
* @param a date 1
|
|
35
|
-
* @param b date 2
|
|
36
|
-
* @returns true if a is later than b
|
|
37
|
-
*/
|
|
38
|
-
export function compareDateString(a: string, b: string): number {
|
|
39
|
-
return Date.parse(a) - Date.parse(b);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Check whether there is an element in b exists in a as well.
|
|
44
|
-
* @param a array 1
|
|
45
|
-
* @param b array 2
|
|
46
|
-
* @returns boolean
|
|
47
|
-
*/
|
|
48
|
-
export function containsAny(a: any[], b: any[]) {
|
|
49
|
-
for (let i of a) {
|
|
50
|
-
for (let j of b) {
|
|
51
|
-
if (i === j) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
package/src/conditionals.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Invoke function or return value if condition is true.
|
|
4
|
-
* @param condition any
|
|
5
|
-
* @param value function to be invoked or value to be return
|
|
6
|
-
* @param defaultValue fallback value, optional
|
|
7
|
-
*/
|
|
8
|
-
export function conditional<T>(condition: any, value: () => void): void;
|
|
9
|
-
export function conditional<T>(condition: any, value: T, defaultValue?: T): T;
|
|
10
|
-
export function conditional<T>(condition: any, value: Supplier<T>, defaultValue?: T): T;
|
|
11
|
-
export function conditional(condition: any, value: any, defaultValue?: any) {
|
|
12
|
-
if (typeof(value) === "function") {
|
|
13
|
-
if (condition) {
|
|
14
|
-
const r = value()
|
|
15
|
-
if (r) {
|
|
16
|
-
return r
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return defaultValue
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof(value === "string")) {
|
|
23
|
-
return condition ? value : (defaultValue || '')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (typeof(value) === "number") {
|
|
27
|
-
return condition ? value : (defaultValue || 0)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (condition) {
|
|
31
|
-
return value
|
|
32
|
-
} else if (defaultValue !== undefined && defaultValue !== null) {
|
|
33
|
-
return defaultValue
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/converters.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { wrapDateNumber } from "./wrappers";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Parse and format timestamp from number to string.
|
|
5
|
-
* @param timestamp time
|
|
6
|
-
* @param showTime show only date if false
|
|
7
|
-
* @param showMilliseconds show ms if true
|
|
8
|
-
* @returns formatted string
|
|
9
|
-
*/
|
|
10
|
-
export function parseTimestamp(timestamp: number, showTime?: boolean, showMilliseconds?: boolean) {
|
|
11
|
-
const date = new Date(timestamp);
|
|
12
|
-
// TODO: toLocaleString
|
|
13
|
-
// return date.toLocaleString(undefined, {
|
|
14
|
-
// });
|
|
15
|
-
let r = `${wrapDateNumber(date.getFullYear())}-${wrapDateNumber(date.getMonth() + 1)}-${wrapDateNumber(date.getDate())}`;
|
|
16
|
-
if (showTime) {
|
|
17
|
-
r += ` ${wrapDateNumber(date.getHours())}:${wrapDateNumber(date.getMinutes())}:${wrapDateNumber(date.getSeconds())}`;
|
|
18
|
-
}
|
|
19
|
-
if (showMilliseconds) {
|
|
20
|
-
r += `.${wrapDateNumber(date.getMilliseconds(), 3)}`;
|
|
21
|
-
};
|
|
22
|
-
return r;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function toCapital(v: string) {
|
|
26
|
-
return v.charAt(0).toUpperCase() + v.substring(1);
|
|
27
|
-
}
|
package/src/functions.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export {}
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
|
|
6
|
-
type Pair<K, V> = [key: K, value: V]
|
|
7
|
-
|
|
8
|
-
type Consumer<T> = (v: T) => void
|
|
9
|
-
|
|
10
|
-
type BiConsumer<A, B> = (a: A, b: B) => void
|
|
11
|
-
|
|
12
|
-
type TriConsumer<A, B, C> = (a: A, b: B, c: C) => void
|
|
13
|
-
|
|
14
|
-
type Func<T, R> = (v: T) => R
|
|
15
|
-
|
|
16
|
-
type BiFunc<A, B, R> = (a: A, b: B) => R
|
|
17
|
-
|
|
18
|
-
type Callback = (...args: any) => any
|
|
19
|
-
|
|
20
|
-
type Supplier<T> = () => T
|
|
21
|
-
|
|
22
|
-
type Comparator<T> = (a: T, b: T) => -1 | 0 | 1
|
|
23
|
-
}
|
package/src/generators.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Genereate a sequence.
|
|
4
|
-
* @param start start
|
|
5
|
-
* @param end end
|
|
6
|
-
* @param step step
|
|
7
|
-
* @returns array
|
|
8
|
-
*/
|
|
9
|
-
export function sequence(start: number, end: number, step: number = 1) {
|
|
10
|
-
const r = [];
|
|
11
|
-
for (let i = start; i < end; i += step) {
|
|
12
|
-
r.push(i);
|
|
13
|
-
}
|
|
14
|
-
return r;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Generate a array of size.
|
|
19
|
-
* @param size size
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
export function iterate(size: number) {
|
|
23
|
-
return Array.from(Array(size).keys())
|
|
24
|
-
}
|
package/src/global.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export { }
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
|
|
6
|
-
interface Mapper<A, B> {
|
|
7
|
-
to?(a: A): B;
|
|
8
|
-
from?(b: B): A;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type Bucket<T> = {
|
|
12
|
-
// (v?: T): T;
|
|
13
|
-
// (v: (prev: T) => T): T;
|
|
14
|
-
<U extends T>(v?: T): U;
|
|
15
|
-
<U extends T>(v: (prev: T) => U): U;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface StampedBucketAction<T> {
|
|
19
|
-
map<O>(call: (v: T) => O): O
|
|
20
|
-
markChanged(): void
|
|
21
|
-
reset(v: T): void
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type StampedBucket<T> = ((updater?: Consumer<T>) => T) & StampedBucketAction<T>;
|
|
25
|
-
|
|
26
|
-
interface StampedData<T> {
|
|
27
|
-
data: T
|
|
28
|
-
timestamp: number
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./arrayHelpers"
|
|
3
|
-
export * from "./buckets"
|
|
4
|
-
export * from "./checks"
|
|
5
|
-
export * from "./converters"
|
|
6
|
-
export * from "./generators"
|
|
7
|
-
export * from "./others"
|
|
8
|
-
export * from "./wrappers"
|
|
9
|
-
export * from "./conditionals"
|
|
10
|
-
|
|
11
|
-
declare global {
|
|
12
|
-
|
|
13
|
-
type ObjectIndex = string | number
|
|
14
|
-
}
|
package/src/others.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Context, useContext } from "solid-js";
|
|
2
|
-
|
|
3
|
-
export function useCtx<T>(c: Context<T>): T {
|
|
4
|
-
const context = useContext(c);
|
|
5
|
-
if (!context) {
|
|
6
|
-
throw new Error("cannot find a " + JSON.stringify(c))
|
|
7
|
-
}
|
|
8
|
-
return context;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function names(...v: (string | undefined)[]) {
|
|
12
|
-
return v.filter((name) => Boolean(name)).join(' ');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function clone(obj: any) {
|
|
16
|
-
const type = typeof(obj);
|
|
17
|
-
switch (type) {
|
|
18
|
-
case 'object': {
|
|
19
|
-
let r: any = Array.isArray(obj) ? [] : {};
|
|
20
|
-
for (let key of Object.keys(obj)) {
|
|
21
|
-
r[key] = clone(obj[key]);
|
|
22
|
-
}
|
|
23
|
-
return r;
|
|
24
|
-
}
|
|
25
|
-
default:
|
|
26
|
-
return obj;
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/wrappers.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function wrapDateNumber(v: number, bits: number = 2) {
|
|
4
|
-
if (v == 0) {
|
|
5
|
-
return '0'.repeat(bits);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let n = v;
|
|
9
|
-
while (n > 0) {
|
|
10
|
-
n = Math.floor(n / 10);
|
|
11
|
-
bits--;
|
|
12
|
-
}
|
|
13
|
-
return bits > 0 ? '0'.repeat(bits) + v : v;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function wrapString(v: any): string {
|
|
17
|
-
if (typeof(v) === "string") {
|
|
18
|
-
return v;
|
|
19
|
-
}
|
|
20
|
-
return v?.toString() || "";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function wrapNumber(v: any) {
|
|
24
|
-
if (typeof(v) === "number") {
|
|
25
|
-
return v;
|
|
26
|
-
}
|
|
27
|
-
return 0;
|
|
28
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": true,
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"strictPropertyInitialization": false,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"jsx": "preserve",
|
|
11
|
-
"jsxImportSource": "solid-js",
|
|
12
|
-
"types": ["vite/client"],
|
|
13
|
-
"noEmit": true,
|
|
14
|
-
"isolatedModules": true,
|
|
15
|
-
"resolveJsonModule": true
|
|
16
|
-
}
|
|
17
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import solidPlugin from 'vite-plugin-solid';
|
|
3
|
-
// import devtools from 'solid-devtools/vite';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
plugins: [
|
|
7
|
-
/*
|
|
8
|
-
Uncomment the following line to enable solid-devtools.
|
|
9
|
-
For more info see https://github.com/thetarnav/solid-devtools/tree/main/packages/extension#readme
|
|
10
|
-
*/
|
|
11
|
-
// devtools(),
|
|
12
|
-
solidPlugin(),
|
|
13
|
-
],
|
|
14
|
-
server: {
|
|
15
|
-
port: 3000,
|
|
16
|
-
},
|
|
17
|
-
build: {
|
|
18
|
-
target: 'esnext',
|
|
19
|
-
},
|
|
20
|
-
});
|