jj 2.4.0 → 2.6.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 (73) hide show
  1. package/README.md +37 -48
  2. package/SKILL.md +671 -0
  3. package/lib/bundle.cjs +2031 -0
  4. package/lib/bundle.cjs.map +1 -0
  5. package/lib/bundle.d.cts +1782 -0
  6. package/lib/bundle.d.ts +1782 -1
  7. package/lib/bundle.global.js +1953 -0
  8. package/lib/bundle.global.js.map +1 -0
  9. package/lib/bundle.js +864 -848
  10. package/lib/bundle.js.map +1 -7
  11. package/lib/bundle.min.cjs +2 -0
  12. package/lib/bundle.min.cjs.map +1 -0
  13. package/lib/bundle.min.d.cts +1782 -0
  14. package/lib/bundle.min.d.ts +1782 -1
  15. package/lib/bundle.min.global.js +2 -0
  16. package/lib/bundle.min.global.js.map +1 -0
  17. package/lib/bundle.min.js +2 -2
  18. package/lib/bundle.min.js.map +1 -0
  19. package/package.json +14 -6
  20. package/lib/JJD.d.ts +0 -76
  21. package/lib/JJD.js +0 -91
  22. package/lib/JJD.js.map +0 -1
  23. package/lib/JJDF.d.ts +0 -60
  24. package/lib/JJDF.js +0 -68
  25. package/lib/JJDF.js.map +0 -1
  26. package/lib/JJE.d.ts +0 -313
  27. package/lib/JJE.js +0 -412
  28. package/lib/JJE.js.map +0 -1
  29. package/lib/JJHE.d.ts +0 -120
  30. package/lib/JJHE.js +0 -164
  31. package/lib/JJHE.js.map +0 -1
  32. package/lib/JJN.d.ts +0 -234
  33. package/lib/JJN.js +0 -323
  34. package/lib/JJN.js.map +0 -1
  35. package/lib/JJSE.d.ts +0 -148
  36. package/lib/JJSE.js +0 -190
  37. package/lib/JJSE.js.map +0 -1
  38. package/lib/JJSR.d.ts +0 -67
  39. package/lib/JJSR.js +0 -85
  40. package/lib/JJSR.js.map +0 -1
  41. package/lib/JJT.d.ts +0 -79
  42. package/lib/JJT.js +0 -108
  43. package/lib/JJT.js.map +0 -1
  44. package/lib/case.d.ts +0 -60
  45. package/lib/case.js +0 -92
  46. package/lib/case.js.map +0 -1
  47. package/lib/case.test.d.ts +0 -1
  48. package/lib/case.test.js +0 -79
  49. package/lib/case.test.js.map +0 -1
  50. package/lib/components.d.ts +0 -147
  51. package/lib/components.js +0 -286
  52. package/lib/components.js.map +0 -1
  53. package/lib/helpers.d.ts +0 -158
  54. package/lib/helpers.js +0 -231
  55. package/lib/helpers.js.map +0 -1
  56. package/lib/index.d.ts +0 -15
  57. package/lib/index.js +0 -16
  58. package/lib/index.js.map +0 -1
  59. package/lib/mixin-types.d.ts +0 -143
  60. package/lib/mixin-types.js +0 -2
  61. package/lib/mixin-types.js.map +0 -1
  62. package/lib/mixins.d.ts +0 -77
  63. package/lib/mixins.js +0 -336
  64. package/lib/mixins.js.map +0 -1
  65. package/lib/types.d.ts +0 -77
  66. package/lib/types.js +0 -2
  67. package/lib/types.js.map +0 -1
  68. package/lib/util.d.ts +0 -96
  69. package/lib/util.js +0 -122
  70. package/lib/util.js.map +0 -1
  71. package/lib/util.test.d.ts +0 -1
  72. package/lib/util.test.js +0 -46
  73. package/lib/util.test.js.map +0 -1
package/lib/JJSR.d.ts DELETED
@@ -1,67 +0,0 @@
1
- import { JJDF } from './JJDF.js';
2
- /**
3
- * Wraps a DOM ShadowRoot node (which is a descendant of DocumentFragment).
4
- *
5
- * @remarks
6
- * The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree
7
- * that is rendered separately from a document's main DOM tree.
8
- *
9
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot | ShadowRoot}
10
- */
11
- export declare class JJSR<T extends ShadowRoot = ShadowRoot> extends JJDF<T> {
12
- /**
13
- * Creates a JJSR instance from a ShadowRoot reference.
14
- *
15
- * @example
16
- * ```ts
17
- * const shadow = JJSR.from(element.shadowRoot)
18
- * ```
19
- *
20
- * @param shadowRoot - The ShadowRoot instance.
21
- * @returns A new JJSR instance.
22
- */
23
- static from(shadowRoot: ShadowRoot): JJSR<ShadowRoot>;
24
- /**
25
- * Creates an instance of JJSR.
26
- *
27
- * @param shadowRoot - The ShadowRoot to wrap.
28
- * @throws {TypeError} If `shadowRoot` is not a ShadowRoot.
29
- */
30
- constructor(shadowRoot: T);
31
- /**
32
- * Gets the inner HTML of the shadow root.
33
- *
34
- * @returns The inner HTML string.
35
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
36
- */
37
- getHTML(): string;
38
- /**
39
- * Sets the inner HTML of the shadow root.
40
- *
41
- * @example
42
- * ```ts
43
- * shadow.setHTML('<p>Hello</p>', false)
44
- * ```
45
- *
46
- * @param value - The HTML string.
47
- * @param unsafe - Reserved for future use (must be false).
48
- * @returns This instance for chaining.
49
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
50
- */
51
- setHTML(value: string, unsafe: false): this;
52
- /**
53
- * Adds constructed stylesheets to the shadow root.
54
- *
55
- * @example
56
- * ```ts
57
- * const sheet = new CSSStyleSheet()
58
- * sheet.replaceSync('p { color: red; }')
59
- * shadow.addStyleSheets(sheet)
60
- * ```
61
- *
62
- * @param styleSheets - The stylesheets to add.
63
- * @returns This instance for chaining.
64
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
65
- */
66
- addStyleSheets(...styleSheets: CSSStyleSheet[]): this;
67
- }
package/lib/JJSR.js DELETED
@@ -1,85 +0,0 @@
1
- import { isA } from 'jty';
2
- import { JJDF } from './JJDF.js';
3
- /**
4
- * Wraps a DOM ShadowRoot node (which is a descendant of DocumentFragment).
5
- *
6
- * @remarks
7
- * The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree
8
- * that is rendered separately from a document's main DOM tree.
9
- *
10
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot | ShadowRoot}
11
- */
12
- export class JJSR extends JJDF {
13
- /**
14
- * Creates a JJSR instance from a ShadowRoot reference.
15
- *
16
- * @example
17
- * ```ts
18
- * const shadow = JJSR.from(element.shadowRoot)
19
- * ```
20
- *
21
- * @param shadowRoot - The ShadowRoot instance.
22
- * @returns A new JJSR instance.
23
- */
24
- static from(shadowRoot) {
25
- return new JJSR(shadowRoot);
26
- }
27
- /**
28
- * Creates an instance of JJSR.
29
- *
30
- * @param shadowRoot - The ShadowRoot to wrap.
31
- * @throws {TypeError} If `shadowRoot` is not a ShadowRoot.
32
- */
33
- constructor(shadowRoot) {
34
- if (!isA(shadowRoot, ShadowRoot)) {
35
- throw new TypeError(`Expected a ShadowRoot. Got ${shadowRoot} (${typeof shadowRoot})`);
36
- }
37
- super(shadowRoot);
38
- }
39
- /**
40
- * Gets the inner HTML of the shadow root.
41
- *
42
- * @returns The inner HTML string.
43
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
44
- */
45
- getHTML() {
46
- return this.ref.innerHTML;
47
- }
48
- /**
49
- * Sets the inner HTML of the shadow root.
50
- *
51
- * @example
52
- * ```ts
53
- * shadow.setHTML('<p>Hello</p>', false)
54
- * ```
55
- *
56
- * @param value - The HTML string.
57
- * @param unsafe - Reserved for future use (must be false).
58
- * @returns This instance for chaining.
59
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML | Element.innerHTML}
60
- */
61
- setHTML(value, unsafe) {
62
- // TODO: https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/setHTMLUnsafe
63
- this.ref.innerHTML = value;
64
- return this;
65
- }
66
- /**
67
- * Adds constructed stylesheets to the shadow root.
68
- *
69
- * @example
70
- * ```ts
71
- * const sheet = new CSSStyleSheet()
72
- * sheet.replaceSync('p { color: red; }')
73
- * shadow.addStyleSheets(sheet)
74
- * ```
75
- *
76
- * @param styleSheets - The stylesheets to add.
77
- * @returns This instance for chaining.
78
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/adoptedStyleSheets | ShadowRoot.adoptedStyleSheets}
79
- */
80
- addStyleSheets(...styleSheets) {
81
- this.ref.adoptedStyleSheets.push(...styleSheets);
82
- return this;
83
- }
84
- }
85
- //# sourceMappingURL=JJSR.js.map
package/lib/JJSR.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"JJSR.js","sourceRoot":"","sources":["../src/JJSR.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;;GAQG;AACH,MAAM,OAAO,IAAwC,SAAQ,IAAO;IAChE;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,CAAC,UAAsB;QAC9B,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,CAAA;IAC/B,CAAC;IAED;;;;;OAKG;IACH,YAAY,UAAa;QACrB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,SAAS,CAAC,8BAA8B,UAAU,KAAK,OAAO,UAAU,GAAG,CAAC,CAAA;QAC1F,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAA;IAC7B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,KAAa,EAAE,MAAa;QAChC,kFAAkF;QAClF,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,KAAK,CAAA;QAC1B,OAAO,IAAI,CAAA;IACf,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,GAAG,WAA4B;QAC1C,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAA;QAChD,OAAO,IAAI,CAAA;IACf,CAAC;CACJ"}
package/lib/JJT.d.ts DELETED
@@ -1,79 +0,0 @@
1
- import { JJN } from './JJN.js';
2
- /**
3
- * Wraps a DOM Text Node.
4
- *
5
- * @remarks
6
- * The Text interface represents the textual content of Element or Attr.
7
- * If an element has no markup within its content, it has a single child implementing Text
8
- * that contains the element's text.
9
- *
10
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Text | Text}
11
- */
12
- export declare class JJT<T extends Text = Text> extends JJN<Text> {
13
- /**
14
- * Creates a JJT instance from a Text node.
15
- *
16
- * @example
17
- * ```ts
18
- * const textNode = document.createTextNode('foo')
19
- * const jjText = JJT.from(textNode)
20
- * ```
21
- *
22
- * @param text - The Text node.
23
- * @returns A new JJT instance.
24
- * @throws {TypeError} If `text` is not a Text node.
25
- */
26
- static from(text: Text): JJT;
27
- /**
28
- * Creates an instance of JJT.
29
- *
30
- * @example
31
- * ```ts
32
- * const text = new JJT('Hello World')
33
- * ```
34
- *
35
- * @param ref - The Text node or a string to create a Text node from.
36
- * @throws {TypeError} If `ref` is not a Text node or string.
37
- */
38
- constructor(ref: T | string);
39
- /**
40
- * Gets the text content.
41
- *
42
- * @returns The text content.
43
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
44
- */
45
- getText(): string;
46
- /**
47
- * Sets the text content.
48
- *
49
- * @example
50
- * ```ts
51
- * text.setText('New content')
52
- * ```
53
- *
54
- * @param text - The text to set.
55
- * @returns This instance for chaining.
56
- * @throws {TypeError} If `text` is not a string.
57
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
58
- */
59
- setText(text: string): this;
60
- /**
61
- * Clears the text content.
62
- *
63
- * @returns This instance for chaining.
64
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
65
- */
66
- empty(): this;
67
- /**
68
- * Sets the text content to multiple lines joined by newline.
69
- *
70
- * @example
71
- * ```ts
72
- * text.addLines('Line 1', 'Line 2')
73
- * ```
74
- *
75
- * @param lines - The lines of text.
76
- * @returns This instance for chaining.
77
- */
78
- addLines(...lines: string[]): this;
79
- }
package/lib/JJT.js DELETED
@@ -1,108 +0,0 @@
1
- import { isA, isStr } from 'jty';
2
- import { JJN } from './JJN.js';
3
- /**
4
- * Wraps a DOM Text Node.
5
- *
6
- * @remarks
7
- * The Text interface represents the textual content of Element or Attr.
8
- * If an element has no markup within its content, it has a single child implementing Text
9
- * that contains the element's text.
10
- *
11
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Text | Text}
12
- */
13
- export class JJT extends JJN {
14
- /**
15
- * Creates a JJT instance from a Text node.
16
- *
17
- * @example
18
- * ```ts
19
- * const textNode = document.createTextNode('foo')
20
- * const jjText = JJT.from(textNode)
21
- * ```
22
- *
23
- * @param text - The Text node.
24
- * @returns A new JJT instance.
25
- * @throws {TypeError} If `text` is not a Text node.
26
- */
27
- static from(text) {
28
- if (!isA(text, Text)) {
29
- throw new TypeError(`Expected a Text object. Got: ${text} (${typeof text})`);
30
- }
31
- return new JJT(text);
32
- }
33
- /**
34
- * Creates an instance of JJT.
35
- *
36
- * @example
37
- * ```ts
38
- * const text = new JJT('Hello World')
39
- * ```
40
- *
41
- * @param ref - The Text node or a string to create a Text node from.
42
- * @throws {TypeError} If `ref` is not a Text node or string.
43
- */
44
- constructor(ref) {
45
- if (isStr(ref)) {
46
- super(document.createTextNode(ref));
47
- }
48
- else if (isA(ref, Text)) {
49
- super(ref);
50
- }
51
- else {
52
- throw new TypeError(`Expected a Text. Got: ${ref} (${typeof ref})`);
53
- }
54
- }
55
- /**
56
- * Gets the text content.
57
- *
58
- * @returns The text content.
59
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
60
- */
61
- getText() {
62
- return this.ref.textContent ?? '';
63
- }
64
- /**
65
- * Sets the text content.
66
- *
67
- * @example
68
- * ```ts
69
- * text.setText('New content')
70
- * ```
71
- *
72
- * @param text - The text to set.
73
- * @returns This instance for chaining.
74
- * @throws {TypeError} If `text` is not a string.
75
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
76
- */
77
- setText(text) {
78
- if (!isStr(text)) {
79
- throw new TypeError(`Expected a string. Got: ${text} (${typeof text})`);
80
- }
81
- this.ref.textContent = text;
82
- return this;
83
- }
84
- /**
85
- * Clears the text content.
86
- *
87
- * @returns This instance for chaining.
88
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
89
- */
90
- empty() {
91
- return this.setText('');
92
- }
93
- /**
94
- * Sets the text content to multiple lines joined by newline.
95
- *
96
- * @example
97
- * ```ts
98
- * text.addLines('Line 1', 'Line 2')
99
- * ```
100
- *
101
- * @param lines - The lines of text.
102
- * @returns This instance for chaining.
103
- */
104
- addLines(...lines) {
105
- return this.setText(lines.join('\n'));
106
- }
107
- }
108
- //# sourceMappingURL=JJT.js.map
package/lib/JJT.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"JJT.js","sourceRoot":"","sources":["../src/JJT.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B;;;;;;;;;GASG;AACH,MAAM,OAAO,GAA2B,SAAQ,GAAS;IACrD;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,IAAI,CAAC,IAAU;QAClB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;YACnB,MAAM,IAAI,SAAS,CAAC,gCAAgC,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,CAAA;QAChF,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC;IAED;;;;;;;;;;OAUG;IACH,YAAY,GAAe;QACvB,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACb,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAA;QACvC,CAAC;aAAM,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACxB,KAAK,CAAC,GAAG,CAAC,CAAA;QACd,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,SAAS,CAAC,yBAAyB,GAAG,KAAK,OAAO,GAAG,GAAG,CAAC,CAAA;QACvE,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;IACrC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAY;QAChB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,SAAS,CAAC,2BAA2B,IAAI,KAAK,OAAO,IAAI,GAAG,CAAC,CAAA;QAC3E,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAA;QAC3B,OAAO,IAAI,CAAA;IACf,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC3B,CAAC;IAED;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,GAAG,KAAe;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACzC,CAAC;CACJ"}
package/lib/case.d.ts DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * Converts a PascalCase, camelCase, or snake_case string to kebab-case.
3
- *
4
- * @remarks
5
- * This function is useful for converting JavaScript property names to CSS or HTML attribute names.
6
- * It strictly validates the input to contain only alphanumeric characters and underscores.
7
- *
8
- * @example
9
- * ```ts
10
- * pas2keb('backgroundColor') // 'background-color'
11
- * pas2keb('MyComponent') // 'my-component'
12
- * pas2keb('user_id') // 'user-id'
13
- * ```
14
- *
15
- * @param str - The string to convert.
16
- * @returns The kebab-case string.
17
- * @throws {TypeError} If `str` is not a string or contains invalid characters (anything other than `/[a-zA-Z0-9_]/`).
18
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | String.prototype.replace}
19
- */
20
- export declare function pas2keb(str: string): string;
21
- /**
22
- * Converts a kebab-case string to PascalCase.
23
- *
24
- * @remarks
25
- * This function splits the string by hyphens and capitalizes the first letter of each segment.
26
- * It handles multiple hyphens by ignoring empty segments.
27
- *
28
- * @example
29
- * ```ts
30
- * keb2pas('background-color') // 'BackgroundColor'
31
- * keb2pas('my-component') // 'MyComponent'
32
- * keb2pas('multi--dash') // 'MultiDash'
33
- * ```
34
- *
35
- * @param str - The string to convert.
36
- * @returns The PascalCase string.
37
- * @throws {TypeError} If `str` is not a string.
38
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split | String.prototype.split}
39
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.prototype.map}
40
- */
41
- export declare function keb2pas(str: string): string;
42
- /**
43
- * Converts a kebab-case string to camelCase.
44
- *
45
- * @remarks
46
- * This function is primarily useful for converting attributes to JavaScript property names.
47
- * Leading and trailing hyphens are removed before conversion.
48
- *
49
- * @example
50
- * ```ts
51
- * keb2cam('background-color') // 'backgroundColor'
52
- * keb2cam('-webkit-transform') // 'webkitTransform'
53
- * ```
54
- *
55
- * @param str - The string to convert.
56
- * @returns The camelCase string.
57
- * @throws {TypeError} If `str` is not a string.
58
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | String.prototype.replace}
59
- */
60
- export declare function keb2cam(str: string): string;
package/lib/case.js DELETED
@@ -1,92 +0,0 @@
1
- import { isStr } from 'jty';
2
- /**
3
- * Converts a PascalCase, camelCase, or snake_case string to kebab-case.
4
- *
5
- * @remarks
6
- * This function is useful for converting JavaScript property names to CSS or HTML attribute names.
7
- * It strictly validates the input to contain only alphanumeric characters and underscores.
8
- *
9
- * @example
10
- * ```ts
11
- * pas2keb('backgroundColor') // 'background-color'
12
- * pas2keb('MyComponent') // 'my-component'
13
- * pas2keb('user_id') // 'user-id'
14
- * ```
15
- *
16
- * @param str - The string to convert.
17
- * @returns The kebab-case string.
18
- * @throws {TypeError} If `str` is not a string or contains invalid characters (anything other than `/[a-zA-Z0-9_]/`).
19
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | String.prototype.replace}
20
- */
21
- export function pas2keb(str) {
22
- if (!isStr(str)) {
23
- throw new TypeError(`Expected a string. Got ${str} (${typeof str})`);
24
- }
25
- if (/[^a-zA-Z0-9_]/.test(str)) {
26
- throw new TypeError(`Invalid characters in string. Only alphanumeric and underscores are allowed. Got: ${str}`);
27
- }
28
- return str
29
- .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
30
- .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
31
- .replace(/_/g, '-')
32
- .toLowerCase();
33
- }
34
- /**
35
- * Converts a kebab-case string to PascalCase.
36
- *
37
- * @remarks
38
- * This function splits the string by hyphens and capitalizes the first letter of each segment.
39
- * It handles multiple hyphens by ignoring empty segments.
40
- *
41
- * @example
42
- * ```ts
43
- * keb2pas('background-color') // 'BackgroundColor'
44
- * keb2pas('my-component') // 'MyComponent'
45
- * keb2pas('multi--dash') // 'MultiDash'
46
- * ```
47
- *
48
- * @param str - The string to convert.
49
- * @returns The PascalCase string.
50
- * @throws {TypeError} If `str` is not a string.
51
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split | String.prototype.split}
52
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map | Array.prototype.map}
53
- */
54
- export function keb2pas(str) {
55
- if (!isStr(str)) {
56
- throw new TypeError(`Expected a string. Got ${str} (${typeof str})`);
57
- }
58
- return (str
59
- .split('-')
60
- .filter(Boolean) // Remove empty strings from leading/trailing/multiple hyphens
61
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
62
- .join('') ||
63
- // Handle strings that were not kebab-case to begin with (e.g. 'single', 'camelCase')
64
- (str.length > 0 ? str.charAt(0).toUpperCase() + str.slice(1) : ''));
65
- }
66
- /**
67
- * Converts a kebab-case string to camelCase.
68
- *
69
- * @remarks
70
- * This function is primarily useful for converting attributes to JavaScript property names.
71
- * Leading and trailing hyphens are removed before conversion.
72
- *
73
- * @example
74
- * ```ts
75
- * keb2cam('background-color') // 'backgroundColor'
76
- * keb2cam('-webkit-transform') // 'webkitTransform'
77
- * ```
78
- *
79
- * @param str - The string to convert.
80
- * @returns The camelCase string.
81
- * @throws {TypeError} If `str` is not a string.
82
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | String.prototype.replace}
83
- */
84
- export function keb2cam(str) {
85
- if (!isStr(str)) {
86
- throw new TypeError(`Expected a string. Got ${str} (${typeof str})`);
87
- }
88
- return str
89
- .replace(/^-+|-+$/g, '') // Remove any leading or trailing hyphens
90
- .replace(/-+([a-z])/g, (g, c) => c.toUpperCase());
91
- }
92
- //# sourceMappingURL=case.js.map
package/lib/case.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"case.js","sourceRoot":"","sources":["../src/case.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAE3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW;IAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,SAAS,CAAC,0BAA0B,GAAG,KAAK,OAAO,GAAG,GAAG,CAAC,CAAA;IACxE,CAAC;IACD,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,qFAAqF,GAAG,EAAE,CAAC,CAAA;IACnH,CAAC;IACD,OAAO,GAAG;SACL,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;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ACzD,CAAC"}
@@ -1 +0,0 @@
1
- export {};
package/lib/case.test.js DELETED
@@ -1,79 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import { pas2keb, keb2pas, keb2cam } from './case.js';
4
- describe('pas2keb()', () => {
5
- it('throws for non-string input', () => {
6
- assert.throws(() => pas2keb(123), TypeError, 'Should throw for a number');
7
- assert.throws(() => pas2keb(true), TypeError, 'Should throw for a boolean');
8
- assert.throws(() => pas2keb(null), TypeError, 'Should throw for null');
9
- assert.throws(() => pas2keb(undefined), TypeError, 'Should throw for undefined');
10
- });
11
- it('converts PascalCase or camelCase to kebab-case', () => {
12
- assert.strictEqual(pas2keb('PascalCase'), 'pascal-case');
13
- assert.strictEqual(pas2keb('camelCase'), 'camel-case');
14
- assert.strictEqual(pas2keb('Hello'), 'hello');
15
- });
16
- it('handles consecutive uppercase letters', () => {
17
- assert.strictEqual(pas2keb('MyHTMLElement'), 'my-html-element');
18
- assert.strictEqual(pas2keb('isURL'), 'is-url');
19
- assert.strictEqual(pas2keb('isURLShortener'), 'is-url-shortener');
20
- });
21
- it('handles edge cases', () => {
22
- assert.strictEqual(pas2keb(''), '', 'Should handle empty string');
23
- assert.strictEqual(pas2keb('A'), 'a');
24
- assert.strictEqual(pas2keb('I'), 'i');
25
- });
26
- it('converts snake_case to kebab-case', () => {
27
- assert.strictEqual(pas2keb('snake_case'), 'snake-case');
28
- assert.strictEqual(pas2keb('Snake_Case'), 'snake-case');
29
- });
30
- });
31
- describe('keb2pas()', () => {
32
- it('throws for non-string input', () => {
33
- assert.throws(() => keb2pas(123), TypeError, 'Should throw for a number');
34
- assert.throws(() => keb2pas(true), TypeError, 'Should throw for a boolean');
35
- assert.throws(() => keb2pas(null), TypeError, 'Should throw for null');
36
- assert.throws(() => keb2pas(undefined), TypeError, 'Should throw for undefined');
37
- });
38
- it('converts kebab-case to PascalCase', () => {
39
- assert.strictEqual(keb2pas('kebab-case'), 'KebabCase');
40
- assert.strictEqual(keb2pas('a-b-c'), 'ABC');
41
- assert.strictEqual(keb2pas('single'), 'Single');
42
- assert.strictEqual(keb2pas('a'), 'A');
43
- });
44
- it('handles edge cases correctly', () => {
45
- assert.strictEqual(keb2pas(''), '', 'Should handle empty string');
46
- assert.strictEqual(keb2pas('foo--bar'), 'FooBar', 'Should handle multiple hyphens');
47
- assert.strictEqual(keb2pas('-foo-bar'), 'FooBar', 'Should handle leading hyphen');
48
- assert.strictEqual(keb2pas('foo-bar-'), 'FooBar', 'Should handle trailing hyphen');
49
- });
50
- it('does not convert other cases', () => {
51
- assert.strictEqual(keb2pas('camelCase'), 'CamelCase', 'Should only capitalize first letter for camelCase');
52
- assert.strictEqual(keb2pas('snake_case'), 'Snake_case', 'Should not convert snake_case');
53
- });
54
- });
55
- describe('keb2cam()', () => {
56
- it('throws for non-string input', () => {
57
- assert.throws(() => keb2cam(123), TypeError, 'Should throw for a number');
58
- assert.throws(() => keb2cam(true), TypeError, 'Should throw for a boolean');
59
- assert.throws(() => keb2cam(null), TypeError, 'Should throw for null');
60
- assert.throws(() => keb2cam(undefined), TypeError, 'Should throw for undefined');
61
- });
62
- it('converts kebab-case to camelCase', () => {
63
- assert.strictEqual(keb2cam('kebab-case'), 'kebabCase');
64
- assert.strictEqual(keb2cam('a-b-c'), 'aBC');
65
- assert.strictEqual(keb2cam('background-color'), 'backgroundColor');
66
- });
67
- it('handles edge cases correctly', () => {
68
- assert.strictEqual(keb2cam(''), '', 'Should handle empty string');
69
- assert.strictEqual(keb2cam('single'), 'single', 'Should handle a single word');
70
- assert.strictEqual(keb2cam('-foo-bar'), 'fooBar', 'Should handle leading hyphen');
71
- assert.strictEqual(keb2cam('baz-quux-'), 'bazQuux', 'Should handle trailing hyphen');
72
- assert.strictEqual(keb2cam('car--tux'), 'carTux', 'Should handle multiple hyphens');
73
- });
74
- it('does not convert other cases', () => {
75
- assert.strictEqual(keb2cam('camelCase'), 'camelCase', 'Should not change camelCase');
76
- assert.strictEqual(keb2cam('snake_case'), 'snake_case', 'Should not convert snake_case');
77
- });
78
- });
79
- //# sourceMappingURL=case.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"case.test.js","sourceRoot":"","sources":["../src/case.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAErD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAU,CAAC,EAAE,SAAS,EAAE,2BAA2B,CAAC,CAAA;QAChF,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAW,CAAC,EAAE,SAAS,EAAE,4BAA4B,CAAC,CAAA;QAClF,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAW,CAAC,EAAE,SAAS,EAAE,uBAAuB,CAAC,CAAA;QAC7E,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,SAAgB,CAAC,EAAE,SAAS,EAAE,4BAA4B,CAAC,CAAA;IAC3F,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,CAAA;QACxD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAA;QACtD,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC7C,M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