ctx-core 5.0.0 → 5.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 (52) hide show
  1. package/all/a_nowrap/index.d.ts +1 -1
  2. package/all/be_/index.test.ts +1 -1
  3. package/all/binary_sort_rank/index.d.ts +3 -2
  4. package/all/deep_equal/index.d.ts +1 -0
  5. package/all/deep_equal/index.js +54 -0
  6. package/all/html/index.d.ts +5 -0
  7. package/all/html/index.js +19 -0
  8. package/all/html/index.test.ts +9 -0
  9. package/all/html_attr/index.d.ts +8 -0
  10. package/all/html_attr/index.js +21 -0
  11. package/all/html_attr/index.test.ts +10 -0
  12. package/all/html_attrs/index.d.ts +6 -0
  13. package/all/html_attrs/index.js +29 -0
  14. package/all/html_attrs/index.test.ts +36 -0
  15. package/all/html_class/index.d.ts +12 -0
  16. package/all/html_class/index.js +34 -0
  17. package/all/html_class/index.test.ts +32 -0
  18. package/all/html_dataset__data_attrs/index.d.ts +2 -0
  19. package/all/html_dataset__data_attrs/index.js +12 -0
  20. package/all/html_dataset__data_attrs/index.test.ts +13 -0
  21. package/all/html_style/index.d.ts +12 -0
  22. package/all/html_style/index.js +49 -0
  23. package/all/html_style/index.test.ts +92 -0
  24. package/all/html_style__assign/index.d.ts +12 -0
  25. package/all/html_style__assign/index.js +20 -0
  26. package/all/html_styles_o/index.d.ts +11 -0
  27. package/all/html_styles_o/index.js +23 -0
  28. package/all/html_styles_o/index.test.ts +10 -0
  29. package/all/index.d.ts +11 -0
  30. package/all/index.js +11 -0
  31. package/all/js_html/index.d.ts +14 -0
  32. package/all/js_html/index.js +21 -0
  33. package/all/links_html/index.d.ts +14 -0
  34. package/all/links_html/index.js +20 -0
  35. package/all/map_apply/index.d.ts +1 -1
  36. package/all/map_apply/index.js +1 -1
  37. package/all/rank/index.d.ts +1 -1
  38. package/all/selector_splice/index.d.ts +1 -1
  39. package/all/slice/index.d.ts +2 -2
  40. package/all/sort/index.d.ts +1 -1
  41. package/all/splice/index.d.ts +2 -2
  42. package/all/wrap_a/index.d.ts +2 -2
  43. package/all/wrap_a_item/index.d.ts +1 -1
  44. package/all/wrap_aa/index.d.ts +1 -1
  45. package/all/wrap_aa_item/index.d.ts +1 -1
  46. package/array/index.d.ts +1 -0
  47. package/array/index.js +1 -0
  48. package/deep_equal/index.d.ts +1 -0
  49. package/deep_equal/index.js +1 -0
  50. package/html/index.d.ts +10 -0
  51. package/html/index.js +10 -0
  52. package/package.json +6 -2
@@ -2,4 +2,4 @@ export declare type a_nowrap_T<I> =
2
2
  I
3
3
  |readonly I[]
4
4
  |readonly I[][]
5
- export declare type ANowrapT = a_nowrap_T
5
+ export declare type ANowrapT<I> = a_nowrap_T<I>
@@ -159,7 +159,7 @@ test('be_|Ctx generic type', ()=>{
159
159
  // @ts-expect-error TS2322
160
160
  throws(()=>val_(ctx_()))
161
161
  })
162
- test('be_|Ctx|NestedMapCtx', ()=>{
162
+ test('be_|Ctx|ns', ()=>{
163
163
  const ctx0 = ctx__new()
164
164
  const ctx1 = ctx__new()
165
165
  ctx1.s[''].set('matching', true)
@@ -2,8 +2,9 @@ import type { compare_1_T } from '../array_types/index.js'
2
2
  /**
3
3
  * Returns the rank of the item where the compare function === 0, using binarySort
4
4
  */
5
- export declare function binary_sort_rank(
6
- a:readonly unknown[], compare_1:compare_1_T
5
+ export declare function binary_sort_rank<I>(
6
+ a:readonly I[],
7
+ compare_1:compare_1_T<I>
7
8
  ):number
8
9
  export {
9
10
  binary_sort_rank as binarySort_rank,
@@ -0,0 +1 @@
1
+ export declare function deep_equal(a:unknown, b:unknown):boolean
@@ -0,0 +1,54 @@
1
+ 'use strict'
2
+ // TODO: Remove when https://github.com/epoberezkin/fast-deep-equal/issues/124 is fixed
3
+ export function deep_equal(a, b) {
4
+ if (a === b) return true
5
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
6
+ if (a.constructor !== b.constructor) return false
7
+ let length, i, keys
8
+ if (Array.isArray(a)) {
9
+ length = a.length
10
+ if (length != b.length) return false
11
+ for (i = length; (i--) !== 0;) if (!deep_equal(a[i], b[i])) return false
12
+ return true
13
+ }
14
+ if (a instanceof Map && b instanceof Map) {
15
+ if (a.size !== b.size) return false
16
+ for (i of a.entries()) if (!b.has(i[0])) return false
17
+ for (i of a.entries()) if (!deep_equal(i[1], b.get(i[0]))) return false
18
+ return true
19
+ }
20
+ if (a instanceof Set && b instanceof Set) {
21
+ if (a.size !== b.size) return false
22
+ for (i of a.entries()) if (!b.has(i[0])) return false
23
+ return true
24
+ }
25
+ if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
26
+ length = a.length
27
+ if (length != b.length) return false
28
+ for (i = length; (i--) !== 0;) if (a[i] !== b[i]) return false
29
+ return true
30
+ }
31
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags
32
+ if (
33
+ a.valueOf !== Object.prototype.valueOf
34
+ && typeof a.valueOf === 'function'
35
+ && typeof b.valueOf === 'function'
36
+ ) return a.valueOf() === b.valueOf()
37
+ if (
38
+ a.toString !== Object.prototype.toString
39
+ && typeof a.toString === 'function'
40
+ && typeof b.toString === 'function'
41
+ ) return a.toString() === b.toString()
42
+ keys = Object.keys(a)
43
+ length = keys.length
44
+ if (length !== Object.keys(b).length) return false
45
+ for (i = length; (i--) !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false
46
+ for (i = length; (i--) !== 0;) {
47
+ let key = keys[i]
48
+ if (!deep_equal(a[key], b[key])) return false
49
+ }
50
+ return true
51
+ }
52
+ // true if both NaN, false otherwise
53
+ return a !== a && b !== b
54
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns a string of escaped html
3
+ */
4
+ export declare function html_(unsafe:string):string
5
+ export { html_ as _html, }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Returns a string of escaped html
3
+ * @param {string}unsafe
4
+ * @returns string
5
+ */
6
+ export function html_(unsafe) {
7
+ return (
8
+ unsafe
9
+ .replace(/&/g, '&amp;')
10
+ .replace(/</g, '&lt;')
11
+ .replace(/>/g, '&gt;')
12
+ .replace(/"/g, '&quot;')
13
+ .replace(/'/g, '&#039;')
14
+ )
15
+ }
16
+ export {
17
+ html_ as html__escape,
18
+ html_ as _html,
19
+ }
@@ -0,0 +1,9 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_ } from './index.js'
4
+ test('html_', ()=>{
5
+ equal(html_(
6
+ `<div>"&'foo'bar"</div>`
7
+ ), '&lt;div&gt;&quot;&amp;&#039;foo&#039;bar&quot;&lt;/div&gt;')
8
+ })
9
+ test.run()
@@ -0,0 +1,8 @@
1
+ import type { nullish } from '../nullish/index.js'
2
+ export declare function html_attr_(key:string, val:string):string
3
+ export { html_attr_ as attr_ }
4
+ export declare function raw__html_attr_(key:string, val:string):string
5
+ export { raw__html_attr_ as raw__attr_ }
6
+ export type html_attr_def_T = Record<string, unknown>|string|string[]|nullish
7
+ export type attr_def_T = html_attr_def_T
8
+
@@ -0,0 +1,21 @@
1
+ import { html_ } from '../html/index.js'
2
+ /**
3
+ * @param {string}key
4
+ * @param {string}val
5
+ * @returns {string}
6
+ * @private
7
+ */
8
+ export function html_attr_(key, val) {
9
+ return key + '="' + html_(val) + '"'
10
+ }
11
+ export { html_attr_ as attr_ }
12
+ /**
13
+ * @param {string}key
14
+ * @param {string}val
15
+ * @returns {string}
16
+ * @private
17
+ */
18
+ export function raw__html_attr_(key, val) {
19
+ return key + '="' + val + '"'
20
+ }
21
+ export { raw__html_attr_ as raw__attr_ }
@@ -0,0 +1,10 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_attr_, raw__html_attr_ } from './index.js'
4
+ test('html_attr_', ()=>{
5
+ equal(html_attr_('id', '123&bar'), 'id="123&amp;bar"')
6
+ })
7
+ test('raw__html_attr_', ()=>{
8
+ equal(raw__html_attr_('id', '123&amp;bar'), 'id="123&amp;bar"')
9
+ })
10
+ test.run()
@@ -0,0 +1,6 @@
1
+ import type { html_attr_def_T } from '../html_attr/index.js'
2
+ /**
3
+ * Returns a string of attrs for an html element
4
+ */
5
+ export declare function html_attrs_(...attr_def_a:html_attr_def_T[]):string
6
+ export { html_attrs_ as attrs_, html_attrs_ as _attrs, }
@@ -0,0 +1,29 @@
1
+ /// <reference types="../attr/index.d.ts" />
2
+ import { html_attr_ } from '../html_attr/index.js'
3
+ import { isArray } from '../isArray/index.js'
4
+ /**
5
+ * Returns a string of attrs for an html element
6
+ * @param {attr_def_T}attr_def_a
7
+ * @returns {string}
8
+ */
9
+ export function html_attrs_(...attr_def_a) {
10
+ /** @type {string[]} */
11
+ let a = []
12
+ for (let i = 0; i < attr_def_a.length; i++) {
13
+ const attr_def = attr_def_a[i]
14
+ if (typeof attr_def === 'string') {
15
+ a.push(attr_def)
16
+ } else if (isArray(attr_def)) {
17
+ a.push(...attr_def)
18
+ } else if (typeof attr_def === 'object') {
19
+ for (const key in attr_def) {
20
+ const val = attr_def[key]
21
+ if (val != null) {
22
+ a.push(html_attr_(key, attr_def[key]))
23
+ }
24
+ }
25
+ }
26
+ }
27
+ return a.join(' ')
28
+ }
29
+ export { html_attrs_ as attrs_, html_attrs_ as _attrs, }
@@ -0,0 +1,36 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_attrs_ } from './index.js'
4
+ test('html_attrs_', ()=>{
5
+ equal(
6
+ html_attrs_('id="foo"', 'class="bar"'),
7
+ 'id="foo" class="bar"')
8
+ equal(
9
+ html_attrs_('id="foo" class="bar"'),
10
+ 'id="foo" class="bar"')
11
+ equal(
12
+ html_attrs_('id="foo"', {
13
+ class: 'bar',
14
+ style: null,
15
+ }),
16
+ 'id="foo" class="bar"')
17
+ equal(
18
+ html_attrs_({
19
+ id: 'foo',
20
+ style: null,
21
+ }, 'class="bar"'),
22
+ 'id="foo" class="bar"')
23
+ equal(
24
+ html_attrs_({
25
+ id: 'foo',
26
+ style: null,
27
+ }, ['class="bar"']),
28
+ 'id="foo" class="bar"')
29
+ equal(
30
+ html_attrs_({
31
+ id: 'foo',
32
+ style: null,
33
+ }, ['class="bar" style="top: 0;"']),
34
+ 'id="foo" class="bar" style="top: 0;"')
35
+ })
36
+ test.run()
@@ -0,0 +1,12 @@
1
+ import { html_attr_def_T } from '../html_attr/index.js'
2
+ /**
3
+ * Returns class html attribute from r
4
+ * @example
5
+ * class_({class_1: true, html_class__: false, class_3: true}) // returns 'class_1 class_3'
6
+ */
7
+ export declare function html_class_(...class_def_a:html_attr_def_T[]):string
8
+ export { html_class_ as class_, html_class_ as _class, }
9
+ export declare function html_class__(
10
+ ...memo_class_def_a:html_attr_def_T[]
11
+ ):(...class_def_a:html_attr_def_T[])=>string
12
+ export { html_class__ as class__, html_class__ as class_2, }
@@ -0,0 +1,34 @@
1
+ /// <reference types="../attr/index.d.ts" />
2
+ import { isArray } from '../isArray/index.js'
3
+ /**
4
+ * Returns class html attribute from r
5
+ * @param {attr_def_T}class_def_a
6
+ * @returns {string}
7
+ * @example
8
+ * class_({class_1: true, html_class__: false, class_3: true}) // returns 'class_1 class_3'
9
+ */
10
+ export function html_class_(...class_def_a) {
11
+ const a = []
12
+ for (let i = 0; i < class_def_a.length; i++) {
13
+ const class_def = class_def_a[i]
14
+ if (typeof class_def === 'string') {
15
+ a.push(class_def)
16
+ } else if (isArray(class_def)) {
17
+ a.push(...class_def)
18
+ } else if (typeof class_def === 'object') {
19
+ for (let key in class_def) {
20
+ if (class_def[key]) a.push(key)
21
+ }
22
+ }
23
+ }
24
+ return a.join(' ')
25
+ }
26
+ export { html_class_ as class_, html_class_ as _class, }
27
+ /**
28
+ * @param {attr_def_T}memo_class_def_a
29
+ * @returns {(...class_def_a:attr_def_T[])=>string}
30
+ */
31
+ export function html_class__(...memo_class_def_a) {
32
+ return (...class_def_a)=>html_class_(...memo_class_def_a, ...class_def_a)
33
+ }
34
+ export { html_class__ as class__, html_class__ as class_2, }
@@ -0,0 +1,32 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_class_, html_class__ } from './index.js'
4
+ test('html_class_', ()=>{
5
+ equal(html_class_('foo', 'bar'), 'foo bar')
6
+ equal(html_class_('foo', {
7
+ bar: true,
8
+ baz: false,
9
+ }), 'foo bar')
10
+ equal(html_class_({
11
+ bar: true,
12
+ baz: false,
13
+ }, 'foo'), 'bar foo')
14
+ equal(html_class_({
15
+ bar: true,
16
+ baz: false,
17
+ }, ['foo']), 'bar foo')
18
+ })
19
+ test('html_class__', ()=>{
20
+ equal(html_class__('foo', 'bar')(), 'foo bar')
21
+ equal(html_class__('foo', {
22
+ bar: true,
23
+ })({ baz: false, }), 'foo bar')
24
+ equal(html_class__({
25
+ baz: false,
26
+ }, 'foo')({ bar: true }), 'foo bar')
27
+ equal(html_class__(['foo'])({
28
+ bar: true,
29
+ baz: false,
30
+ }), 'foo bar')
31
+ })
32
+ test.run()
@@ -0,0 +1,2 @@
1
+ export declare function html_dataset__data_attrs_<R extends Record<string, unknown>>(dataset:R):R
2
+ export { html_dataset__data_attrs_ as dataset__data_attrs_ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @param {Record<string, any>}dataset
3
+ * @returns {Record<string, any>}
4
+ * @private
5
+ */
6
+ export function html_dataset__data_attrs_(dataset) {
7
+ return Object.entries(dataset).reduce((o, [key, value])=>{
8
+ o[`data-${key}`] = value
9
+ return o
10
+ }, {})
11
+ }
12
+ export { html_dataset__data_attrs_ as dataset__data_attrs_ }
@@ -0,0 +1,13 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_dataset__data_attrs_ } from './index.js'
4
+ test('html_dataset__data_attrs_', ()=>{
5
+ equal(html_dataset__data_attrs_({
6
+ foo: 'bar',
7
+ baz: 123
8
+ }), {
9
+ 'data-foo': 'bar',
10
+ 'data-baz': 123,
11
+ })
12
+ })
13
+ test.run()
@@ -0,0 +1,12 @@
1
+ import type { html_attr_def_T } from '../html_attr/index.js'
2
+ /**
3
+ * Returns class style attribute from obj
4
+ * @example
5
+ * style_({position: 'absolute, left: '5px'}) // returns 'position: absolute; left: 5px;'
6
+ */
7
+ export declare function html_style_(...style_def_a:html_attr_def_T[]):string
8
+ export { html_style_ as style_, html_style_ as _style, }
9
+ export declare function html_style__(
10
+ ...memo_style_def_a:html_attr_def_T[]
11
+ ):(...style_def_a:html_attr_def_T[])=>string
12
+ export { html_style__ as style__, html_style__ as style_2, }
@@ -0,0 +1,49 @@
1
+ /// <reference types="../attr/index.d.ts" />
2
+ import { isArray } from '../isArray/index.js'
3
+ const eol_semicolon_regex = /;\s*$/
4
+ /**
5
+ * Returns class style attribute from obj
6
+ * @param {attr_def_T}style_def_a
7
+ * @returns {string}
8
+ * @example
9
+ * style_({position: 'absolute, left: '5px'}) // returns 'position: absolute; left: 5px;'
10
+ */
11
+ export function html_style_(...style_def_a) {
12
+ const a = []
13
+ for (let i = 0; i < style_def_a.length; i++) {
14
+ const style_def = style_def_a[i]
15
+ if (typeof style_def === 'string') {
16
+ a.push(semicolon__style_(style_def))
17
+ } else if (isArray(style_def)) {
18
+ a.push(...style_def.map($=>semicolon__style_($)))
19
+ } else if (typeof style_def === 'object') {
20
+ for (let key in style_def) {
21
+ const val = style_def[key]
22
+ if (val != null) a.push(`${key}: ${val};`)
23
+ }
24
+ }
25
+ }
26
+ return a.join(' ')
27
+ }
28
+ export { html_style_ as style_, html_style_ as _style, }
29
+ /**
30
+ * @param {string}style
31
+ * @returns {string}
32
+ * @private
33
+ */
34
+ function semicolon__style_(style) {
35
+ return (
36
+ eol_semicolon_regex.test(style)
37
+ ? style
38
+ : `${style};`
39
+ )
40
+ }
41
+ /**
42
+ * @param {attr_def_T}memo_style_def_a
43
+ * @returns {(...style_def_a:string[])=>string}
44
+ * @private
45
+ */
46
+ export function html_style__(memo_style_def_a) {
47
+ return (...style_a)=>html_style_(memo_style_def_a, ...style_a)
48
+ }
49
+ export { html_style__ as style__, html_style__ as style_2, }
@@ -0,0 +1,92 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_style_, html_style__ } from './index.js'
4
+ test('html_style_', ()=>{
5
+ equal(
6
+ html_style_('display: block', 'position: absolute'),
7
+ 'display: block; position: absolute;')
8
+ equal(
9
+ html_style_('display: block; position: absolute;'),
10
+ 'display: block; position: absolute;')
11
+ equal(
12
+ html_style_('display: block', {
13
+ position: 'absolute',
14
+ top: null,
15
+ }),
16
+ 'display: block; position: absolute;')
17
+ equal(
18
+ html_style_({
19
+ display: 'block',
20
+ top: null,
21
+ }, 'position: absolute'),
22
+ 'display: block; position: absolute;')
23
+ equal(
24
+ html_style_({
25
+ display: 'block',
26
+ top: null,
27
+ }, ['position: absolute']),
28
+ 'display: block; position: absolute;')
29
+ equal(
30
+ html_style_({
31
+ display: 'block',
32
+ top: null,
33
+ }, ['position: absolute; top: 0']),
34
+ 'display: block; position: absolute; top: 0;')
35
+ equal(
36
+ html_style_({
37
+ display: 'block',
38
+ top: null,
39
+ }, ['position: absolute; top: 0']),
40
+ 'display: block; position: absolute; top: 0;')
41
+ equal(
42
+ html_style_({
43
+ display: 'block',
44
+ top: null,
45
+ }, ['position: absolute; top: 0;']),
46
+ 'display: block; position: absolute; top: 0;')
47
+ })
48
+ test('html_style__', ()=>{
49
+ equal(
50
+ html_style__('display: block')('position: absolute'),
51
+ 'display: block; position: absolute;')
52
+ equal(
53
+ html_style__('display: block;')('position: absolute;'),
54
+ 'display: block; position: absolute;')
55
+ equal(
56
+ html_style__('display: block')({
57
+ position: 'absolute',
58
+ top: null,
59
+ }),
60
+ 'display: block; position: absolute;')
61
+ equal(
62
+ html_style__({
63
+ display: 'block',
64
+ top: null,
65
+ })('position: absolute'),
66
+ 'display: block; position: absolute;')
67
+ equal(
68
+ html_style__({
69
+ display: 'block',
70
+ top: null,
71
+ })(['position: absolute']),
72
+ 'display: block; position: absolute;')
73
+ equal(
74
+ html_style__({
75
+ display: 'block',
76
+ top: null,
77
+ })(['position: absolute; top: 0']),
78
+ 'display: block; position: absolute; top: 0;')
79
+ equal(
80
+ html_style__({
81
+ display: 'block',
82
+ top: null,
83
+ })(['position: absolute; top: 0']),
84
+ 'display: block; position: absolute; top: 0;')
85
+ equal(
86
+ html_style__({
87
+ display: 'block',
88
+ top: null,
89
+ })(['position: absolute; top: 0;']),
90
+ 'display: block; position: absolute; top: 0;')
91
+ })
92
+ test.run()
@@ -0,0 +1,12 @@
1
+ import type { html_attr_def_T } from '../html_attr/index.js'
2
+ /**
3
+ * Assigns additional styles to the style attribute on the HTMLElement el.
4
+ */
5
+ export declare function html_style__assign(
6
+ el:HTMLElement, ...style_def_a:html_attr_def_T[]
7
+ ):HTMLElement
8
+ export {
9
+ html_style__assign as assign_style,
10
+ html_style__assign as assign__style,
11
+ html_style__assign as style__assign,
12
+ }
@@ -0,0 +1,20 @@
1
+ /// <reference types="../attr/index.d.ts" />
2
+ import { html_style_ } from '../html_style/index.js'
3
+ import { html_styles_o_ } from '../html_styles_o/index.js'
4
+ /**
5
+ * Assigns additional styles to the style attribute on the HTMLElement el.
6
+ * @param el{HTMLElement}
7
+ * @param {attr_def_T}style_def_a
8
+ * @returns {HTMLElement}
9
+ * */
10
+ export function html_style__assign(el, ...style_def_a) {
11
+ const el_style = el.getAttribute('style') || ''
12
+ const styles_o = html_styles_o_(el_style)
13
+ el.setAttribute('style', html_style_(styles_o, ...style_def_a))
14
+ return el
15
+ }
16
+ export {
17
+ html_style__assign as assign_style,
18
+ html_style__assign as assign__style,
19
+ html_style__assign as style__assign,
20
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Parses a style string & returns an object with each style
3
+ * @example
4
+ * html_styles_o_('position: absolute; left: 5px;') // returns {position: 'absolute, left: '5px'}
5
+ */
6
+ export declare function html_styles_o_(style_str:string):Record<string, string>
7
+ export {
8
+ html_styles_o_ as _styles_o,
9
+ html_styles_o_ as _OBJ__styles,
10
+ html_styles_o_ as styles_o_,
11
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Parses a style string & returns an object with each style
3
+ * @param {string}style_str
4
+ * @returns {Record<string, string>}
5
+ * @example
6
+ * html_styles_o_('position: absolute; left: 5px;') // returns {position: 'absolute, left: '5px'}
7
+ */
8
+ export function html_styles_o_(style_str) {
9
+ const style_str_a = (style_str || '').split(/ *; */)
10
+ const styles_o = {}
11
+ for (let i = 0; i < style_str_a.length; i++) {
12
+ const i_style_str = style_str_a[i]
13
+ if (!i_style_str) continue
14
+ const [style_name, style_value] = i_style_str.split(/ *: */)
15
+ styles_o[style_name] = style_value
16
+ }
17
+ return styles_o
18
+ }
19
+ export {
20
+ html_styles_o_ as _styles_o,
21
+ html_styles_o_ as _OBJ__styles,
22
+ html_styles_o_ as styles_o_,
23
+ }
@@ -0,0 +1,10 @@
1
+ import { test } from 'uvu'
2
+ import { equal } from 'uvu/assert'
3
+ import { html_styles_o_ } from './index.js'
4
+ test('html_styles_o_', ()=>{
5
+ equal(html_styles_o_('position: absolute; top: 0;'), {
6
+ position: 'absolute',
7
+ top: '0'
8
+ })
9
+ })
10
+ test.run()
package/all/index.d.ts CHANGED
@@ -101,6 +101,7 @@ export * from './day_seconds/index.js'
101
101
  export * from './debounce/index.js'
102
102
  export * from './debounce_mapreduce/index.js'
103
103
  export * from './deep_clone/index.js'
104
+ export * from './deep_equal/index.js'
104
105
  export * from './defaults/index.js'
105
106
  export * from './deg_rad/index.js'
106
107
  export * from './diff_date/index.js'
@@ -166,6 +167,14 @@ export * from './hour/index.js'
166
167
  export * from './hour/index.js'
167
168
  export * from './hour_seconds/index.js'
168
169
  export * from './hour_seconds/index.js'
170
+ export * from './html/index.js'
171
+ export * from './html_attr/index.js'
172
+ export * from './html_attrs/index.js'
173
+ export * from './html_class/index.js'
174
+ export * from './html_dataset__data_attrs/index.js'
175
+ export * from './html_style/index.js'
176
+ export * from './html_style__assign/index.js'
177
+ export * from './html_styles_o/index.js'
169
178
  export * from './http__headers__assign/index.js'
170
179
  export * from './http_error/index.js'
171
180
  export * from './idx/index.js'
@@ -201,6 +210,7 @@ export * from './isObject/index.js'
201
210
  export * from './isPrimitive/index.js'
202
211
  export * from './isPromiseLike/index.js'
203
212
  export * from './item_r_idx/index.js'
213
+ export * from './js_html/index.js'
204
214
  export * from './key_compare/index.js'
205
215
  export * from './key_r/index.js'
206
216
  export * from './key_r_a/index.js'
@@ -209,6 +219,7 @@ export * from './keys/index.js'
209
219
  export * from './last/index.js'
210
220
  export * from './left_and/index.js'
211
221
  export * from './left_or/index.js'
222
+ export * from './links_html/index.js'
212
223
  export * from './lte_0_a/index.js'
213
224
  export * from './m_m_yyyy/index.js'
214
225
  export * from './m_yy/index.js'
package/all/index.js CHANGED
@@ -101,6 +101,7 @@ export * from './day_seconds/index.js'
101
101
  export * from './debounce/index.js'
102
102
  export * from './debounce_mapreduce/index.js'
103
103
  export * from './deep_clone/index.js'
104
+ export * from './deep_equal/index.js'
104
105
  export * from './defaults/index.js'
105
106
  export * from './deg_rad/index.js'
106
107
  export * from './diff_date/index.js'
@@ -166,6 +167,14 @@ export * from './hour/index.js'
166
167
  export * from './hour/index.js'
167
168
  export * from './hour_seconds/index.js'
168
169
  export * from './hour_seconds/index.js'
170
+ export * from './html/index.js'
171
+ export * from './html_attr/index.js'
172
+ export * from './html_attrs/index.js'
173
+ export * from './html_class/index.js'
174
+ export * from './html_dataset__data_attrs/index.js'
175
+ export * from './html_style/index.js'
176
+ export * from './html_style__assign/index.js'
177
+ export * from './html_styles_o/index.js'
169
178
  export * from './http__headers__assign/index.js'
170
179
  export * from './http_error/index.js'
171
180
  export * from './idx/index.js'
@@ -201,6 +210,7 @@ export * from './isObject/index.js'
201
210
  export * from './isPrimitive/index.js'
202
211
  export * from './isPromiseLike/index.js'
203
212
  export * from './item_r_idx/index.js'
213
+ export * from './js_html/index.js'
204
214
  export * from './key_compare/index.js'
205
215
  export * from './key_r/index.js'
206
216
  export * from './key_r_a/index.js'
@@ -209,6 +219,7 @@ export * from './keys/index.js'
209
219
  export * from './last/index.js'
210
220
  export * from './left_and/index.js'
211
221
  export * from './left_or/index.js'
222
+ export * from './links_html/index.js'
212
223
  export * from './lte_0_a/index.js'
213
224
  export * from './m_m_yyyy/index.js'
214
225
  export * from './m_yy/index.js'
@@ -0,0 +1,14 @@
1
+ /**
2
+ * html for js script tags
3
+ */
4
+ export declare function js_html_(params:js_html__params_T):string
5
+ export interface js_html__params_T {
6
+ js:string[]
7
+ script:string[]
8
+ indentation:string
9
+ }
10
+ export type js_html__opts_T = js_html__params_T
11
+ export {
12
+ js_html_ as _js_html,
13
+ js_html_ as _html__js,
14
+ }
@@ -0,0 +1,21 @@
1
+ /// <reference types="index.d.ts" />
2
+ /**
3
+ * html for js script tags
4
+ * @param {js_html__params_T}params
5
+ * @returns {string}
6
+ */
7
+ export function js_html_(params) {
8
+ const indentation = params.indentation ?? ''
9
+ const script = params.script || params.js || []
10
+ let js_html_a = []
11
+ for (let i = 0; i < script.length; i++) {
12
+ const js_file = script[i]
13
+ js_html_a.push(
14
+ `${indentation}<script type="text/javascript" src="${js_file}"></script>`)
15
+ }
16
+ return js_html_a.join('\n')
17
+ }
18
+ export {
19
+ js_html_ as _js_html,
20
+ js_html_ as _html__js,
21
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * html for css link tags
3
+ */
4
+ export declare function links_html_(params:links_html__params_T):string
5
+ export interface links_html__params_T {
6
+ css:string[]
7
+ indentation:string
8
+ }
9
+ export type links_html__opts_T = links_html__params_T
10
+ export {
11
+ links_html_ as _links_html,
12
+ links_html_ as _html__links,
13
+ }
14
+
@@ -0,0 +1,20 @@
1
+ /// <reference types="./index.d.ts" />
2
+ /**
3
+ * html for css link tags
4
+ * @param {links_html__params_T}params
5
+ * @returns {string}
6
+ */
7
+ export function links_html_(params) {
8
+ const css = params.css ?? []
9
+ const indentation = params.indentation ?? ''
10
+ let links_html_a = []
11
+ for (let i = 0; i < css.length; i++) {
12
+ const css_file = css[i]
13
+ links_html_a.push(`${indentation}<link rel="stylesheet" type="text/css" href="${css_file}">`)
14
+ }
15
+ return links_html_a.join('\n')
16
+ }
17
+ export {
18
+ links_html_ as _links_html,
19
+ links_html_ as _html__links,
20
+ }
@@ -3,7 +3,7 @@ import type { map_fn_T } from '../map_fn/index.js'
3
3
  * Returns function that returns map of calls to fn_a applying in_arg_a with ...arg_a_
4
4
  */
5
5
  export declare function map_apply_<Arg, O>(
6
- fn_a:map_fn_T[],
6
+ fn_a:map_fn_T<Arg, O>[],
7
7
  in_arg_a?:Arg[]
8
8
  ):(...fn_arg_a:Arg[])=>O[]
9
9
  export declare type map_apply_T<Arg, O> = (...fn_arg_a:Arg[])=>O[]
@@ -6,7 +6,7 @@ import { concat } from '../concat/index.js'
6
6
  * @returns {(...fn_arg_a:unknown[])=>unknown[]}
7
7
  */
8
8
  export function map_apply_(fn_a, in_arg_a = []) {
9
- return (...fn_arg_a)=>fn_a.map((fn)=>fn(...concat(in_arg_a, fn_arg_a)))
9
+ return (...fn_arg_a)=>fn_a.map(fn=>fn(...concat(in_arg_a, fn_arg_a)))
10
10
  }
11
11
  export {
12
12
  map_apply_ as map_fn_apply_fn,
@@ -4,6 +4,6 @@ import type { compare_1_T } from '../array_types/index.js'
4
4
  */
5
5
  export declare function rank<I>(
6
6
  a:readonly I[],
7
- compare_1:compare_1_T
7
+ compare_1:compare_1_T<I>
8
8
  ):number
9
9
  export { rank as rank__a1, }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * splice out any `array` elements matching `selector`
3
3
  */
4
- export declare function selector_splice<I, O extends unknown[] = readonly I[]>(
4
+ export declare function selector_splice<I, O extends unknown[] = I[]>(
5
5
  a:readonly I[],
6
6
  selector:(v:I, i:number, a:readonly I[])=>I
7
7
  ):O
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Calls slice on a
3
3
  */
4
- export declare function slice<I, O extends unknown[] = readonly I[]>(
4
+ export declare function slice<I, O extends unknown[] = I[]>(
5
5
  a:readonly I[],
6
6
  begin_idx?:number,
7
7
  end_idx?:number
8
8
  ):O
9
- export declare function maybe_slice<I, O extends unknown[] = readonly I[], Or = null>(
9
+ export declare function maybe_slice<I, O extends unknown[] = I[], Or = null>(
10
10
  maybe_a:readonly I[]|undefined,
11
11
  begin_idx?:number,
12
12
  end_idx?:number,
@@ -2,7 +2,7 @@ import type { compare_T } from '../array_types/index.js'
2
2
  /**
3
3
  * Sort items in `a` by the `compare` function
4
4
  */
5
- export declare function sort<I, O extends unknown[] = readonly I[]>(
5
+ export declare function sort<I, O extends unknown[] = I[]>(
6
6
  a:readonly I[], compare?:compare_T<I>
7
7
  ):O
8
8
  export declare function maybe_sort<I, O = readonly I[], Or = null>(
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Calls splice on a
3
3
  */
4
- export declare function splice<I, O extends unknown[] = readonly I[]>(
4
+ export declare function splice<I, O extends unknown[] = I[]>(
5
5
  a:readonly I[],
6
6
  start:number,
7
7
  delete_count?:number,
8
8
  ...arg_a:readonly I[]
9
9
  ):O
10
- export declare function maybe_splice<I, O extends unknown[] = readonly I[]>(
10
+ export declare function maybe_splice<I, O extends unknown[] = I[]>(
11
11
  maybe_a:readonly I[]|undefined,
12
12
  start:number,
13
13
  delete_count?:number,
@@ -15,8 +15,8 @@ export declare type wrap_a_T<I> =
15
15
  I extends readonly unknown[]
16
16
  ? I
17
17
  : readonly I[]
18
- export declare type wrap_a1_T = wrap_a_T
19
- export declare type wrap_a1_type = wrap_a_T
18
+ export declare type wrap_a1_T<I> = wrap_a_T<I>
19
+ export declare type wrap_a1_type<I> = wrap_a_T<I>
20
20
  export declare type wrap_a_T2<I> =
21
21
  |readonly I[]
22
22
  |readonly I[][]
@@ -3,4 +3,4 @@ export declare type wrap_a_item_T<I> =
3
3
  wrap_a_T<I> extends readonly (infer O)[][]
4
4
  ? O
5
5
  : never
6
- export declare type wrap_a1_item_type = wrap_a_item_T
6
+ export declare type wrap_a1_item_type<I> = wrap_a_item_T<I>
@@ -14,4 +14,4 @@ export declare type wrap_aa_T<I> = (
14
14
  : I extends readonly unknown[]
15
15
  ? readonly I[]
16
16
  : readonly I[][])
17
- export declare type wrap_aa_type = wrap_aa_T
17
+ export declare type wrap_aa_type<I> = wrap_aa_T<I>
@@ -3,4 +3,4 @@ export declare type wrap_aa_item_T<I> =
3
3
  wrap_aa_T<I> extends readonly (infer O)[][]
4
4
  ? O
5
5
  : never
6
- export declare type wrapA2ItemT = wrap_aa_item_T
6
+ export declare type wrapA2ItemT<I> = wrap_aa_item_T<I>
package/array/index.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from '../all/every/index.js'
21
21
  export * from '../all/filter/index.js'
22
22
  export * from '../all/find/index.js'
23
23
  export * from '../all/first/index.js'
24
+ export * from '../all/flatten/index.js'
24
25
  export * from '../all/gte_0_a/index.js'
25
26
  export * from '../all/has_multiple/index.js'
26
27
  export * from '../all/idx/index.js'
package/array/index.js CHANGED
@@ -21,6 +21,7 @@ export * from '../all/every/index.js'
21
21
  export * from '../all/filter/index.js'
22
22
  export * from '../all/find/index.js'
23
23
  export * from '../all/first/index.js'
24
+ export * from '../all/flatten/index.js'
24
25
  export * from '../all/gte_0_a/index.js'
25
26
  export * from '../all/has_multiple/index.js'
26
27
  export * from '../all/idx/index.js'
@@ -0,0 +1 @@
1
+ export * from '../all/deep_equal/index.js'
@@ -0,0 +1 @@
1
+ export * from '../all/deep_equal/index.js'
@@ -0,0 +1,10 @@
1
+ export * from '../all/html_attr/index.js'
2
+ export * from '../all/html_attrs/index.js'
3
+ export * from '../all/html_class/index.js'
4
+ export * from '../all/html_dataset__data_attrs/index.js'
5
+ export * from '../all/html/index.js'
6
+ export * from '../all/js_html/index.js'
7
+ export * from '../all/links_html/index.js'
8
+ export * from '../all/html_style/index.js'
9
+ export * from '../all/html_style__assign/index.js'
10
+ export * from '../all/html_styles_o/index.js'
package/html/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export * from '../all/html_attr/index.js'
2
+ export * from '../all/html_attrs/index.js'
3
+ export * from '../all/html_class/index.js'
4
+ export * from '../all/html_dataset__data_attrs/index.js'
5
+ export * from '../all/html/index.js'
6
+ export * from '../all/js_html/index.js'
7
+ export * from '../all/links_html/index.js'
8
+ export * from '../all/html_style/index.js'
9
+ export * from '../all/html_style__assign/index.js'
10
+ export * from '../all/html_styles_o/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctx-core",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "ctx-core core library",
5
5
  "keywords": [
6
6
  "ctx-core",
@@ -41,11 +41,13 @@
41
41
  "data",
42
42
  "date",
43
43
  "debounce",
44
+ "deep_equal",
44
45
  "error",
45
46
  "fetch",
46
47
  "fibonacci",
47
48
  "function",
48
49
  "functional",
50
+ "html",
49
51
  "http",
50
52
  "math",
51
53
  "matrix",
@@ -85,11 +87,13 @@
85
87
  "./data": "./data/index.js",
86
88
  "./date": "./date/index.js",
87
89
  "./debounce": "./debounce/index.js",
90
+ "./deep_equal": "./deep_equal/index.js",
88
91
  "./error": "./error/index.js",
89
92
  "./fetch": "./fetch/index.js",
90
93
  "./fibonacci": "./fibonacci/index.js",
91
94
  "./function": "./function/index.js",
92
95
  "./functional": "./functional/index.js",
96
+ "./html": "./html/index.js",
93
97
  "./http": "./http/index.js",
94
98
  "./math": "./math/index.js",
95
99
  "./matrix": "./matrix/index.js",
@@ -119,7 +123,7 @@
119
123
  "check-dts": "^0.7.2",
120
124
  "sinon": "^17.0.1",
121
125
  "size-limit": "^11.0.1",
122
- "tsx": "^4.6.2",
126
+ "tsx": "^4.7.0",
123
127
  "typescript": "next",
124
128
  "uvu": "^0.5.6"
125
129
  },