solid-tiny-utils 0.2.0 → 0.3.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.
@@ -0,0 +1,8 @@
1
+ // src/lodash/async.ts
2
+ var sleep = (milliseconds) => {
3
+ return new Promise((res) => setTimeout(res, milliseconds));
4
+ };
5
+
6
+ export {
7
+ sleep
8
+ };
@@ -0,0 +1,85 @@
1
+ // src/lodash/str.ts
2
+ var capitalize = (str) => {
3
+ if (!str || str.length === 0) {
4
+ return "";
5
+ }
6
+ const lower = str.toLowerCase();
7
+ return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length);
8
+ };
9
+ var splitRegexp = /(?=[A-Z])|[.\-\s_]/;
10
+ var camel = (str) => {
11
+ const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
12
+ if (parts.length === 0) {
13
+ return "";
14
+ }
15
+ if (parts.length === 1) {
16
+ return parts[0];
17
+ }
18
+ return parts.reduce((acc, part) => {
19
+ return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}`;
20
+ });
21
+ };
22
+ var splitOnNumberRegexp = /([A-Za-z]{1}[0-9]{1})/;
23
+ var snake = (str, options) => {
24
+ const parts = str?.replace(/([A-Z])+/g, capitalize).split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
25
+ if (parts.length === 0) {
26
+ return "";
27
+ }
28
+ if (parts.length === 1) {
29
+ return parts[0];
30
+ }
31
+ const result = parts.reduce((acc, part) => {
32
+ return `${acc}_${part.toLowerCase()}`;
33
+ });
34
+ return options?.splitOnNumber === false ? result : result.replace(splitOnNumberRegexp, (val) => `${val[0]}_${val[1]}`);
35
+ };
36
+ var dash = (str) => {
37
+ const parts = str?.replace(/([A-Z])+/g, capitalize)?.split(splitRegexp).map((x) => x.toLowerCase()) ?? [];
38
+ if (parts.length === 0) {
39
+ return "";
40
+ }
41
+ if (parts.length === 1) {
42
+ return parts[0];
43
+ }
44
+ return parts.reduce((acc, part) => {
45
+ return `${acc}-${part.toLowerCase()}`;
46
+ });
47
+ };
48
+ var pascalSplitRegexp = /[.\-\s_]/;
49
+ var pascal = (str) => {
50
+ const parts = str?.split(pascalSplitRegexp).map((x) => x.toLowerCase()) ?? [];
51
+ if (parts.length === 0) {
52
+ return "";
53
+ }
54
+ return parts.map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
55
+ };
56
+ var title = (str) => {
57
+ if (!str) {
58
+ return "";
59
+ }
60
+ return str.split(splitRegexp).map((s) => s.trim()).filter((s) => !!s).map((s) => capitalize(s.toLowerCase())).join(" ");
61
+ };
62
+ var template = (str, data, regex = /\{\{(.+?)\}\}/g) => {
63
+ return Array.from(str.matchAll(regex)).reduce((acc, match) => {
64
+ return acc.replace(match[0], data[match[1]]);
65
+ }, str);
66
+ };
67
+ var trim = (str, charsToTrim = " ") => {
68
+ if (!str) {
69
+ return "";
70
+ }
71
+ const toTrim = charsToTrim.replace(/[\W]{1}/g, "\\$&");
72
+ const regex = new RegExp(`^[${toTrim}]+|[${toTrim}]+$`, "g");
73
+ return str.replace(regex, "");
74
+ };
75
+
76
+ export {
77
+ capitalize,
78
+ camel,
79
+ snake,
80
+ dash,
81
+ pascal,
82
+ title,
83
+ template,
84
+ trim
85
+ };
package/dist/dom/css.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  mountStyle
3
3
  } from "../chunk-KVG6TCSE.js";
4
- import "../chunk-33ZRZ4S2.js";
4
+ import "../chunk-OECLQ3OT.js";
5
+ import "../chunk-KFWZFQMB.js";
5
6
  import "../chunk-RRYFZNKE.js";
6
7
  import "../chunk-WLQ64SAO.js";
7
8
  import "../chunk-ZGYORUAX.js";
9
+ import "../chunk-PNR5G432.js";
8
10
  export {
9
11
  mountStyle
10
12
  };
package/dist/dom/index.js CHANGED
@@ -2,10 +2,12 @@ import "../chunk-FFBJP5FE.js";
2
2
  import {
3
3
  mountStyle
4
4
  } from "../chunk-KVG6TCSE.js";
5
- import "../chunk-33ZRZ4S2.js";
5
+ import "../chunk-OECLQ3OT.js";
6
+ import "../chunk-KFWZFQMB.js";
6
7
  import "../chunk-RRYFZNKE.js";
7
8
  import "../chunk-WLQ64SAO.js";
8
9
  import "../chunk-ZGYORUAX.js";
10
+ import "../chunk-PNR5G432.js";
9
11
  export {
10
12
  mountStyle
11
13
  };
@@ -4,10 +4,12 @@ import {
4
4
  import "../chunk-ZZNAXGNU.js";
5
5
  import "../chunk-M5A3VVYI.js";
6
6
  import "../chunk-4L6FK7MF.js";
7
- import "../chunk-33ZRZ4S2.js";
7
+ import "../chunk-OECLQ3OT.js";
8
+ import "../chunk-KFWZFQMB.js";
8
9
  import "../chunk-RRYFZNKE.js";
9
10
  import "../chunk-WLQ64SAO.js";
10
11
  import "../chunk-ZGYORUAX.js";
12
+ import "../chunk-PNR5G432.js";
11
13
  export {
12
14
  createClickOutside
13
15
  };
@@ -5,10 +5,12 @@ import {
5
5
  import "../chunk-ZZNAXGNU.js";
6
6
  import "../chunk-M5A3VVYI.js";
7
7
  import "../chunk-4L6FK7MF.js";
8
- import "../chunk-33ZRZ4S2.js";
8
+ import "../chunk-OECLQ3OT.js";
9
+ import "../chunk-KFWZFQMB.js";
9
10
  import "../chunk-RRYFZNKE.js";
10
11
  import "../chunk-WLQ64SAO.js";
11
12
  import "../chunk-ZGYORUAX.js";
13
+ import "../chunk-PNR5G432.js";
12
14
  export {
13
15
  createClickOutside
14
16
  };
@@ -4,10 +4,12 @@ import {
4
4
  import "../chunk-ZZNAXGNU.js";
5
5
  import "../chunk-M5A3VVYI.js";
6
6
  import "../chunk-4L6FK7MF.js";
7
- import "../chunk-33ZRZ4S2.js";
7
+ import "../chunk-OECLQ3OT.js";
8
+ import "../chunk-KFWZFQMB.js";
8
9
  import "../chunk-RRYFZNKE.js";
9
10
  import "../chunk-WLQ64SAO.js";
10
11
  import "../chunk-ZGYORUAX.js";
12
+ import "../chunk-PNR5G432.js";
11
13
  export {
12
14
  createDebounce
13
15
  };
@@ -4,10 +4,12 @@ import {
4
4
  import "../chunk-ZZNAXGNU.js";
5
5
  import "../chunk-M5A3VVYI.js";
6
6
  import "../chunk-4L6FK7MF.js";
7
- import "../chunk-33ZRZ4S2.js";
7
+ import "../chunk-OECLQ3OT.js";
8
+ import "../chunk-KFWZFQMB.js";
8
9
  import "../chunk-RRYFZNKE.js";
9
10
  import "../chunk-WLQ64SAO.js";
10
11
  import "../chunk-ZGYORUAX.js";
12
+ import "../chunk-PNR5G432.js";
11
13
  export {
12
14
  createLoopExec
13
15
  };
package/dist/fn/index.js CHANGED
@@ -10,10 +10,12 @@ import {
10
10
  import "../chunk-ZZNAXGNU.js";
11
11
  import "../chunk-M5A3VVYI.js";
12
12
  import "../chunk-4L6FK7MF.js";
13
- import "../chunk-33ZRZ4S2.js";
13
+ import "../chunk-OECLQ3OT.js";
14
+ import "../chunk-KFWZFQMB.js";
14
15
  import "../chunk-RRYFZNKE.js";
15
16
  import "../chunk-WLQ64SAO.js";
16
17
  import "../chunk-ZGYORUAX.js";
18
+ import "../chunk-PNR5G432.js";
17
19
  export {
18
20
  createDebounce,
19
21
  createLoopExec,
package/dist/index.d.ts CHANGED
@@ -2,8 +2,10 @@ export { mountStyle } from './dom/css.js';
2
2
  export { createClickOutside } from './event/create-click-outside.js';
3
3
  export { noop } from './fn/index.js';
4
4
  export { iterate, list, range } from './lodash/array.js';
5
+ export { sleep } from './lodash/async.js';
5
6
  export { isArray, isClient, isDate, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol } from './lodash/is.js';
6
7
  export { draw, random, shuffle, uid } from './lodash/random.js';
8
+ export { camel, capitalize, dash, pascal, snake, template, title, trim } from './lodash/str.js';
7
9
  export { access } from './reactive/access.js';
8
10
  export { createWatch } from './reactive/create-watch.js';
9
11
  export { MaybeAccessor, MaybeArray, MaybePromise } from './types/maybe.js';
package/dist/index.js CHANGED
@@ -24,7 +24,10 @@ import {
24
24
  import {
25
25
  createWatch
26
26
  } from "./chunk-4L6FK7MF.js";
27
- import "./chunk-33ZRZ4S2.js";
27
+ import "./chunk-OECLQ3OT.js";
28
+ import {
29
+ sleep
30
+ } from "./chunk-KFWZFQMB.js";
28
31
  import {
29
32
  draw,
30
33
  random,
@@ -51,12 +54,25 @@ import {
51
54
  isString,
52
55
  isSymbol
53
56
  } from "./chunk-ZGYORUAX.js";
57
+ import {
58
+ camel,
59
+ capitalize,
60
+ dash,
61
+ pascal,
62
+ snake,
63
+ template,
64
+ title,
65
+ trim
66
+ } from "./chunk-PNR5G432.js";
54
67
  export {
55
68
  access,
69
+ camel,
70
+ capitalize,
56
71
  createClickOutside,
57
72
  createDebounce,
58
73
  createLoopExec,
59
74
  createWatch,
75
+ dash,
60
76
  draw,
61
77
  isArray,
62
78
  isClient,
@@ -75,8 +91,14 @@ export {
75
91
  list,
76
92
  mountStyle,
77
93
  noop,
94
+ pascal,
78
95
  random,
79
96
  range,
80
97
  shuffle,
98
+ sleep,
99
+ snake,
100
+ template,
101
+ title,
102
+ trim,
81
103
  uid
82
104
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Async wait
3
+ */
4
+ declare const sleep: (milliseconds: number) => Promise<unknown>;
5
+
6
+ export { sleep };
@@ -0,0 +1,6 @@
1
+ import {
2
+ sleep
3
+ } from "../chunk-KFWZFQMB.js";
4
+ export {
5
+ sleep
6
+ };
@@ -1,3 +1,5 @@
1
1
  export { iterate, list, range } from './array.js';
2
+ export { sleep } from './async.js';
2
3
  export { isArray, isClient, isDate, isEmpty, isFloat, isFn, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol } from './is.js';
3
4
  export { draw, random, shuffle, uid } from './random.js';
5
+ export { camel, capitalize, dash, pascal, snake, template, title, trim } from './str.js';
@@ -1,4 +1,7 @@
1
- import "../chunk-33ZRZ4S2.js";
1
+ import "../chunk-OECLQ3OT.js";
2
+ import {
3
+ sleep
4
+ } from "../chunk-KFWZFQMB.js";
2
5
  import {
3
6
  draw,
4
7
  random,
@@ -25,7 +28,20 @@ import {
25
28
  isString,
26
29
  isSymbol
27
30
  } from "../chunk-ZGYORUAX.js";
31
+ import {
32
+ camel,
33
+ capitalize,
34
+ dash,
35
+ pascal,
36
+ snake,
37
+ template,
38
+ title,
39
+ trim
40
+ } from "../chunk-PNR5G432.js";
28
41
  export {
42
+ camel,
43
+ capitalize,
44
+ dash,
29
45
  draw,
30
46
  isArray,
31
47
  isClient,
@@ -42,8 +58,14 @@ export {
42
58
  isSymbol,
43
59
  iterate,
44
60
  list,
61
+ pascal,
45
62
  random,
46
63
  range,
47
64
  shuffle,
65
+ sleep,
66
+ snake,
67
+ template,
68
+ title,
69
+ trim,
48
70
  uid
49
71
  };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Capitalize the first word of the string
3
+ *
4
+ * capitalize('hello') -> 'Hello'
5
+ * capitalize('va va voom') -> 'Va va voom'
6
+ */
7
+ declare const capitalize: (str: string) => string;
8
+ /**
9
+ * Formats the given string in camel case fashion
10
+ *
11
+ * camel('hello world') -> 'helloWorld'
12
+ * camel('va va-VOOM') -> 'vaVaVoom'
13
+ * camel('helloWorld') -> 'helloWorld'
14
+ */
15
+ declare const camel: (str: string) => string;
16
+ /**
17
+ * Formats the given string in snake case fashion
18
+ *
19
+ * splitOnNumber? Treat number as capital, default is true
20
+ *
21
+ * snake('hello world') -> 'hello_world'
22
+ * snake('va va-VOOM') -> 'va_va_voom'
23
+ * snake('helloWord') -> 'hello_world'
24
+ */
25
+ declare const snake: (str: string, options?: {
26
+ splitOnNumber?: boolean;
27
+ }) => string;
28
+ /**
29
+ * Formats the given string in dash case fashion
30
+ *
31
+ * dash('hello world') -> 'hello-world'
32
+ * dash('va va_VOOM') -> 'va-va-voom'
33
+ * dash('helloWord') -> 'hello-word'
34
+ */
35
+ declare const dash: (str: string) => string;
36
+ /**
37
+ * Formats the given string in pascal case fashion
38
+ *
39
+ * pascal('hello world') -> 'HelloWorld'
40
+ * pascal('va va boom') -> 'VaVaBoom'
41
+ */
42
+ declare const pascal: (str: string) => string;
43
+ /**
44
+ * Formats the given string in title case fashion
45
+ *
46
+ * title('hello world') -> 'Hello World'
47
+ * title('va_va_boom') -> 'Va Va Boom'
48
+ * title('root-hook') -> 'Root Hook'
49
+ * title('queryItems') -> 'Query Items'
50
+ */
51
+ declare const title: (str: string | null | undefined) => string;
52
+ /**
53
+ * template is used to replace data by name in template strings.
54
+ * The default expression looks for {{name}} to identify names.
55
+ *
56
+ * Ex. template('Hello, {{name}}', { name: 'ray' })
57
+ * Ex. template('Hello, <name>', { name: 'ray' }, /<(.+?)>/g)
58
+ */
59
+ declare const template: (str: string, data: Record<string, any>, regex?: RegExp) => string;
60
+ /**
61
+ * Trims all prefix and suffix characters from the given
62
+ * string. Like the builtin trim function but accepts
63
+ * other characters you would like to trim and trims
64
+ * multiple characters.
65
+ *
66
+ * ```typescript
67
+ * trim(' hello ') // => 'hello'
68
+ * trim('__hello__', '_') // => 'hello'
69
+ * trim('/repos/:owner/:repo/', '/') // => 'repos/:owner/:repo'
70
+ * trim('222222__hello__1111111', '12_') // => 'hello'
71
+ * ```
72
+ */
73
+ declare const trim: (str: string | null | undefined, charsToTrim?: string) => string;
74
+
75
+ export { camel, capitalize, dash, pascal, snake, template, title, trim };
@@ -0,0 +1,20 @@
1
+ import {
2
+ camel,
3
+ capitalize,
4
+ dash,
5
+ pascal,
6
+ snake,
7
+ template,
8
+ title,
9
+ trim
10
+ } from "../chunk-PNR5G432.js";
11
+ export {
12
+ camel,
13
+ capitalize,
14
+ dash,
15
+ pascal,
16
+ snake,
17
+ template,
18
+ title,
19
+ trim
20
+ };
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  access
3
3
  } from "../chunk-M5A3VVYI.js";
4
- import "../chunk-33ZRZ4S2.js";
4
+ import "../chunk-OECLQ3OT.js";
5
+ import "../chunk-KFWZFQMB.js";
5
6
  import "../chunk-RRYFZNKE.js";
6
7
  import "../chunk-WLQ64SAO.js";
7
8
  import "../chunk-ZGYORUAX.js";
9
+ import "../chunk-PNR5G432.js";
8
10
  export {
9
11
  access
10
12
  };
@@ -5,10 +5,12 @@ import {
5
5
  import {
6
6
  createWatch
7
7
  } from "../chunk-4L6FK7MF.js";
8
- import "../chunk-33ZRZ4S2.js";
8
+ import "../chunk-OECLQ3OT.js";
9
+ import "../chunk-KFWZFQMB.js";
9
10
  import "../chunk-RRYFZNKE.js";
10
11
  import "../chunk-WLQ64SAO.js";
11
12
  import "../chunk-ZGYORUAX.js";
13
+ import "../chunk-PNR5G432.js";
12
14
  export {
13
15
  access,
14
16
  createWatch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-tiny-utils",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A collection of tiny utilities for SolidJS applications",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
File without changes