dirac-lang 0.1.2

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 (110) hide show
  1. package/.env.example +8 -0
  2. package/COMMUNITY.md +465 -0
  3. package/LIBRARIES.md +172 -0
  4. package/NAMESPACES.md +366 -0
  5. package/PROMOTION.md +257 -0
  6. package/QUICKSTART-LIBRARY.md +93 -0
  7. package/README.md +257 -0
  8. package/config.yml +6 -0
  9. package/config.yml.openai +4 -0
  10. package/dirac-http/examples/demo.di +9 -0
  11. package/dirac-http/lib/index.di +12 -0
  12. package/dist/chunk-NDIRTD3D.js +217 -0
  13. package/dist/chunk-S625X7ME.js +1071 -0
  14. package/dist/cli.d.ts +1 -0
  15. package/dist/cli.js +261 -0
  16. package/dist/index.d.ts +144 -0
  17. package/dist/index.js +22 -0
  18. package/dist/session-4QG7OERD.js +42 -0
  19. package/examples/add-demo.di +74 -0
  20. package/examples/add.bk +11 -0
  21. package/examples/advanced-math-demo.di +53 -0
  22. package/examples/calculator.di +32 -0
  23. package/examples/comprehensive.bk +29 -0
  24. package/examples/defvar-variable-demo.di +18 -0
  25. package/examples/direct-call.di +17 -0
  26. package/examples/disk-analysis.di +16 -0
  27. package/examples/executable-hello.di +7 -0
  28. package/examples/execute-demo.di +38 -0
  29. package/examples/file-manager.di +77 -0
  30. package/examples/file-stats.di +18 -0
  31. package/examples/hello.bk +1 -0
  32. package/examples/hello.di +5 -0
  33. package/examples/import-demo.di +31 -0
  34. package/examples/inline-test.bk +7 -0
  35. package/examples/lib/advanced-math.di +81 -0
  36. package/examples/lib/fileops.di +26 -0
  37. package/examples/lib/math.di +25 -0
  38. package/examples/lib/mongodb.di +96 -0
  39. package/examples/llm-agent.di +32 -0
  40. package/examples/llm-basic.di +12 -0
  41. package/examples/llm-command-no-exec.di +13 -0
  42. package/examples/llm-command.di +13 -0
  43. package/examples/llm-complex.di +141 -0
  44. package/examples/llm-recursive.di +31 -0
  45. package/examples/llm-reflection-test.di +19 -0
  46. package/examples/llm-subs.di +132 -0
  47. package/examples/llm-use-subs.di +6 -0
  48. package/examples/loop.di +12 -0
  49. package/examples/math-test.di +22 -0
  50. package/examples/mongodb-count-events.di +8 -0
  51. package/examples/mongodb-import-demo.di +25 -0
  52. package/examples/mongodb-simple-test.di +18 -0
  53. package/examples/nl-agent.di +47 -0
  54. package/examples/parameters-demo.di +68 -0
  55. package/examples/params-test.di +10 -0
  56. package/examples/recipe-chain.di +38 -0
  57. package/examples/recursive-llm.di +44 -0
  58. package/examples/sample-library/README.md +152 -0
  59. package/examples/sample-library/examples/demo.di +34 -0
  60. package/examples/sample-library/lib/index.di +65 -0
  61. package/examples/sample-library/package.json +31 -0
  62. package/examples/seamless.di +45 -0
  63. package/examples/shell-test.bk +10 -0
  64. package/examples/simple-import.di +13 -0
  65. package/examples/simple-recursive.di +26 -0
  66. package/examples/story-builder.di +45 -0
  67. package/examples/subroutine.di +23 -0
  68. package/examples/system-llm.di +21 -0
  69. package/examples/system-simple.di +3 -0
  70. package/examples/system-test.di +13 -0
  71. package/examples/task-assistant.di +27 -0
  72. package/examples/test-parameters.di +50 -0
  73. package/examples/two-styles.di +28 -0
  74. package/examples/var-debug.di +6 -0
  75. package/examples/var-inline.di +4 -0
  76. package/examples/var-test2.di +6 -0
  77. package/examples/variable-simple.di +16 -0
  78. package/examples/variable-test.di +22 -0
  79. package/filePath +1 -0
  80. package/greeting.txt +1 -0
  81. package/package.json +41 -0
  82. package/src/cli.ts +118 -0
  83. package/src/index.ts +33 -0
  84. package/src/llm/ollama.ts +58 -0
  85. package/src/runtime/braket-parser.ts +234 -0
  86. package/src/runtime/interpreter.ts +135 -0
  87. package/src/runtime/parser.ts +151 -0
  88. package/src/runtime/session.ts +228 -0
  89. package/src/tags/assign.ts +37 -0
  90. package/src/tags/call.ts +156 -0
  91. package/src/tags/defvar.ts +56 -0
  92. package/src/tags/eval.ts +68 -0
  93. package/src/tags/execute.ts +52 -0
  94. package/src/tags/expr.ts +128 -0
  95. package/src/tags/if.ts +58 -0
  96. package/src/tags/import.ts +66 -0
  97. package/src/tags/index.ts +37 -0
  98. package/src/tags/llm.ts +207 -0
  99. package/src/tags/loop.ts +43 -0
  100. package/src/tags/mongodb.ts +70 -0
  101. package/src/tags/output.ts +23 -0
  102. package/src/tags/parameters.ts +79 -0
  103. package/src/tags/require_module.ts +19 -0
  104. package/src/tags/subroutine.ts +52 -0
  105. package/src/tags/system.ts +70 -0
  106. package/src/tags/variable.ts +25 -0
  107. package/src/types/index.ts +101 -0
  108. package/src/utils/llm-adapter.ts +113 -0
  109. package/tools/create-library.sh +175 -0
  110. package/tsconfig.json +19 -0
@@ -0,0 +1,31 @@
1
+ <!-- Recursive LLM - LLM calling Dirac calling LLM -->
2
+ <dirac>
3
+ <!-- Define a subroutine that gets stock info -->
4
+ <subroutine name="getStockPrice">
5
+ <parameters>
6
+ <variable name="symbol" passby="value" />
7
+ </parameters>
8
+
9
+ <LLM output="price" maxTokens="50">
10
+ What is the current approximate stock price of ${symbol}?
11
+ Respond with just a number (e.g., "150.23").
12
+ </LLM>
13
+
14
+ <output>${symbol}: $${price}</output>
15
+ </subroutine>
16
+
17
+ <!-- LLM decides which stocks to check -->
18
+ <LLM output="response">
19
+ List 3 major tech stocks to check, one per line.
20
+ Format: SYMBOL only (e.g., "AAPL")
21
+ </LLM>
22
+
23
+ <output>Checking stocks from LLM: ${response}&#10;&#10;</output>
24
+
25
+ <!-- In the future, this could parse ${response} and call getStockPrice for each -->
26
+ <call name="getStockPrice">
27
+ <parameters>
28
+ <variable value="AAPL" />
29
+ </parameters>
30
+ </call>
31
+ </dirac>
@@ -0,0 +1,19 @@
1
+ <dirac>
2
+ <subroutine name="inventory" description="Show you the inventory" >
3
+ you have reachded the inventory
4
+ </subroutine>
5
+
6
+ <subroutine name="order" description="Places an order for an item." param-item="string:required:Item name" param-quantity="number:required:Quantity">
7
+ <parameters select="@item"/>
8
+ <parameters select="@quantity"/>
9
+ <output>
10
+ this is my item: <variable name="item" />
11
+ and <variable name="quantity" />
12
+ </output>
13
+ </subroutine>
14
+
15
+ <llm execute="true">Show me my inventory</llm>
16
+ <llm execute="true">Order 2 apples</llm>
17
+
18
+
19
+ </dirac>
@@ -0,0 +1,132 @@
1
+ <dirac>
2
+ <!-- UI Control Services -->
3
+ <!-- These subroutines are exposed as natural language endpoints -->
4
+
5
+ <subroutine name="background"
6
+ description="Change the background color, do not generate other tags like <changeBackground /> use precise tag"
7
+ param-color="string:required:Background color:red|blue|green|yellow|orange|purple|pink|white|black">
8
+ <parameters select="@color"/>
9
+
10
+ <eval>
11
+ console.log('Changing background color to: ' + color);
12
+ </eval>
13
+ </subroutine>
14
+
15
+ <subroutine name="set-text-size"
16
+ description="Adjust the text size"
17
+ param-size="string:required:Font size:12px|14px|16px|18px|20px|24px">
18
+ <parameters select="@size" />
19
+ <eval>
20
+ console.log("change text size to "+size );
21
+ document.body.style.fontSize = '${size}';
22
+ </eval>
23
+ </subroutine>
24
+
25
+ <subroutine name="reset-styles"
26
+ description="Reset all styles to default">
27
+ <eval>
28
+ console.log("reset all styles back");
29
+ document.body.style.backgroundColor = 'white';
30
+ document.body.style.fontSize = '16px';
31
+ </eval>
32
+ </subroutine>
33
+
34
+ <subroutine name="text-color"
35
+ description="Change the text color"
36
+ param-color="string:required:Text color:black|white|red|blue|green">
37
+ <parameters select="@color" />
38
+ <eval>
39
+ console.log("change color of text to "+color);
40
+ document.body.style.color = '${color}';
41
+ </eval>
42
+ </subroutine>
43
+
44
+ <!-- Event Generation Examples -->
45
+
46
+ <subroutine name="click-button"
47
+ description="Simulate clicking a button"
48
+ param-selector="string:optional:CSS selector (default: #submit-button)">
49
+ <eval>
50
+ const selector = '${selector}' || '#submit-button';
51
+ const element = document.querySelector(selector);
52
+ if (element) {
53
+ const clickEvent = new MouseEvent('click', {
54
+ bubbles: true,
55
+ cancelable: true,
56
+ view: window
57
+ });
58
+ element.dispatchEvent(clickEvent);
59
+ } else {
60
+ throw new Error('Element not found: ' + selector);
61
+ }
62
+ </eval>
63
+ </subroutine>
64
+
65
+ <subroutine name="type-text"
66
+ description="Type text into an input field"
67
+ param-text="string:required:Text to type"
68
+ param-field="string:optional:Which field:name|email">
69
+ <parameters select="@text" />
70
+ <parameters select="@field" />
71
+ <eval>
72
+ const _field = typeof field !== 'undefined' && field ? field : 'name';
73
+ const selector = _field === 'email' ? '#email-input' : '#name-input';
74
+ const input = document.querySelector(selector);
75
+ if (input) {
76
+ input.value = text;
77
+ input.dispatchEvent(new Event('input', { bubbles: true }));
78
+ input.dispatchEvent(new Event('change', { bubbles: true }));
79
+ } else {
80
+ throw new Error('Input not found: ' + selector);
81
+ }
82
+ </eval>
83
+ </subroutine>
84
+
85
+ <subroutine name="check-terms"
86
+ description="Check or uncheck the terms checkbox"
87
+ param-checked="string:optional:Check state:true|false">
88
+ <eval>
89
+ const shouldCheck = '${checked}' !== 'false';
90
+ const checkbox = document.querySelector('#terms-checkbox');
91
+ if (checkbox) {
92
+ checkbox.checked = shouldCheck;
93
+ checkbox.dispatchEvent(new Event('change', { bubbles: true }));
94
+ } else {
95
+ throw new Error('Checkbox not found');
96
+ }
97
+ </eval>
98
+ </subroutine>
99
+
100
+ <subroutine name="clear-input"
101
+ description="Clear an input field"
102
+ param-field="string:optional:Which field:name|email">
103
+ <eval>
104
+ const field = '${field}' || 'name';
105
+ const selector = field === 'email' ? '#email-input' : '#name-input';
106
+ const input = document.querySelector(selector);
107
+ if (input) {
108
+ input.value = '';
109
+ input.dispatchEvent(new Event('input', { bubbles: true }));
110
+ input.dispatchEvent(new Event('change', { bubbles: true }));
111
+ } else {
112
+ throw new Error('Input not found: ' + selector);
113
+ }
114
+ </eval>
115
+ </subroutine>
116
+
117
+ <!--
118
+ <subroutine name="modify-file"
119
+ description="modify a file based on pattern and replacement field "
120
+ param-filename="string|required"
121
+ param-pattern="string|required"
122
+ param-replace="string|required"
123
+ >
124
+ <parameters select="@filename" />
125
+ <parameters select="@pattern" />
126
+ <parameters select="@replace" />
127
+ <system>
128
+ sed -e 's/${pattern}/${replace}/g' ${filename}
129
+ </system>
130
+ </subroutine>
131
+ -->
132
+ </dirac>
@@ -0,0 +1,6 @@
1
+ <dirac>
2
+ <import src="llm-subs.di" />
3
+ <llm execute="true">set the background color to red</llm>
4
+
5
+
6
+ </dirac>
@@ -0,0 +1,12 @@
1
+ <!-- Loop and conditional test -->
2
+ <dirac>
3
+ <defvar name="result" value="" />
4
+
5
+ <loop count="5" var="i">
6
+ <eval name="isEven" expr="i % 2 === 0" />
7
+
8
+ <if test="${isEven} == true">
9
+ <output>${i} is even&#10;</output>
10
+ </if>
11
+ </loop>
12
+ </dirac>
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env dirac
2
+ <dirac>
3
+ <import src="./lib/math.di" />
4
+
5
+ <output>Math Library Test&#10;&#10;</output>
6
+
7
+ <defvar name="x" value="8" />
8
+ <output>Square of ${x}: </output>
9
+ <call name="SQUARE" />
10
+ <output>&#10;</output>
11
+
12
+ <defvar name="a" value="15" />
13
+ <defvar name="b" value="25" />
14
+ <output>${a} + ${b} = </output>
15
+ <call name="ADD" />
16
+ <output>&#10;</output>
17
+
18
+ <defvar name="num" value="6" />
19
+ <output>Factorial of ${num}: </output>
20
+ <call name="FACTORIAL" />
21
+ <output>&#10;</output>
22
+ </dirac>
@@ -0,0 +1,8 @@
1
+
2
+
3
+ <dirc >
4
+ <mongodb database="betting" collection="events" action="find">
5
+ { }
6
+ </mongodb>
7
+
8
+ </dirac>
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env dirac
2
+ <!-- Demo: Using MongoDB extension library -->
3
+ <dirac>
4
+
5
+
6
+ <subroutine name="MONGODB">
7
+ <parameters select="@database" />
8
+ <parameters select="@collection" />
9
+ <defvar name="body"><parameters select="*"/></defvar>
10
+ <!-- <defvar name="body">some body</defvar> -->
11
+
12
+ <output>database is: <variable name="database" />&#10;</output>
13
+ <output>collection is: <variable name="collection" />&#10;</output>
14
+ <output>query is: <variable name="body" />&#10;</output>
15
+ <output>from dirac&#10;</output>
16
+
17
+
18
+ </subroutine>
19
+
20
+
21
+ <MONGODB database="betting" collection="events" action="find">
22
+ hi, this is a test
23
+ </MONGODB>
24
+
25
+ </dirac>
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env dirac
2
+ <!-- Simple MongoDB extension test -->
3
+ <dirac>
4
+
5
+
6
+ <!-- Import the MongoDB extension library -->
7
+ <import src="./lib/mongodb.di" />
8
+
9
+
10
+ <MONGODB database="betting" collection="events" action="find">{ "type.name": "Pass" }</MONGODB>
11
+
12
+ <!--
13
+ <output>Testing MongoDB count:&#10;</output>
14
+
15
+ <MONGODB database="betting" collection="events" action="count">{ "type.name": "Pass" }</MONGODB>
16
+ -->
17
+
18
+ </dirac>
@@ -0,0 +1,47 @@
1
+ <!-- Advanced Agent - Natural language to operations -->
2
+ <dirac>
3
+ <output>Interactive Agent Example&#10;&#10;</output>
4
+
5
+ <!-- Task 1: File operations -->
6
+ <defvar name="userRequest" value="count how many .di files are in examples directory" />
7
+
8
+ <output>Request: ${userRequest}&#10;</output>
9
+ <LLM output="code1" maxTokens="300">
10
+ Generate Dirac XML to: ${userRequest}
11
+
12
+ Use these tags ONLY:
13
+ 1. &lt;eval name="varname"&gt;return javascriptExpression;&lt;/eval&gt;
14
+ 2. &lt;output&gt;text with ${varname}&lt;/output&gt;
15
+
16
+ Example:
17
+ &lt;dirac&gt;
18
+ &lt;eval name="result"&gt;return fs.readdirSync('examples').filter(f =&gt; f.endsWith('.di')).length;&lt;/eval&gt;
19
+ &lt;output&gt;Count: ${result}&lt;/output&gt;
20
+ &lt;/dirac&gt;
21
+
22
+ Return only XML, no markdown or explanations.
23
+ </LLM>
24
+
25
+ <output>Executing...&#10;</output>
26
+ <execute source="code1" />
27
+ <output>&#10;&#10;</output>
28
+
29
+ <!-- Task 2: Data processing -->
30
+ <assign name="userRequest" value="create a JSON file with current date and time" />
31
+
32
+ <output>Request: ${userRequest}&#10;</output>
33
+ <LLM output="code2" maxTokens="300">
34
+ Generate Dirac XML to: ${userRequest}
35
+
36
+ Available:
37
+ - &lt;eval name="var"&gt;return jsExpression&lt;/eval&gt; (MUST use 'return', fs and path available, can use Date)
38
+ - &lt;output&gt;text ${variable}&lt;/output&gt;
39
+
40
+ IMPORTANT: Every eval MUST have 'return' statement.
41
+ Return only &lt;dirac&gt; XML, no markdown. Name the file timestamp.json.
42
+ </LLM>
43
+
44
+ <output>Executing...&#10;</output>
45
+ <execute source="code2" />
46
+ <output>&#10;</output>
47
+ </dirac>
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env dirac
2
+ <dirac>
3
+ <!--
4
+ Parameters Tag Example
5
+
6
+ The <parameters> tag allows subroutines to access their caller's
7
+ children and attributes, enabling functional-style parameter passing.
8
+
9
+ select="*" - Execute all child elements of caller
10
+ select="@attr" - Emit specific attribute value
11
+ select="@*" - Emit all attributes as name="value" pairs
12
+ -->
13
+
14
+ <!-- Example 1: Functional wrapper with child content -->
15
+ <subroutine name="BOLD">
16
+ <output>&lt;b&gt;</output>
17
+ <parameters select="*"/>
18
+ <output>&lt;/b&gt;</output>
19
+ </subroutine>
20
+
21
+ <output>Example 1: </output>
22
+ <BOLD>
23
+ <output>Hello World</output>
24
+ </BOLD>
25
+ <output>&#10;</output>
26
+
27
+ <!-- Example 2: Attribute passthrough -->
28
+ <subroutine name="ATTR_DEMO">
29
+ <output>a=</output>
30
+ <parameters select="@a"/>
31
+ <output>, b=</output>
32
+ <parameters select="@b"/>
33
+ </subroutine>
34
+
35
+ <output>Example 2: </output>
36
+ <ATTR_DEMO a="3" b="4"/>
37
+ <output>&#10;</output>
38
+
39
+ <!-- Example 3: Inspector showing all attributes -->
40
+ <subroutine name="INSPECT">
41
+ <output>Element attributes: [</output>
42
+ <parameters select="@*"/>
43
+ <output>]&#10;</output>
44
+ </subroutine>
45
+
46
+ <output>Example 3:&#10;</output>
47
+ <INSPECT id="widget-1" type="button" enabled="true"/>
48
+
49
+ <!-- Example 4: List formatter -->
50
+ <subroutine name="UL">
51
+ <output>&lt;ul&gt;&#10;</output>
52
+ <parameters select="*"/>
53
+ <output>&lt;/ul&gt;&#10;</output>
54
+ </subroutine>
55
+
56
+ <subroutine name="LI">
57
+ <output> &lt;li&gt;</output>
58
+ <parameters select="*"/>
59
+ <output>&lt;/li&gt;&#10;</output>
60
+ </subroutine>
61
+
62
+ <output>Example 4:&#10;</output>
63
+ <UL>
64
+ <LI><output>First item</output></LI>
65
+ <LI><output>Second item</output></LI>
66
+ <LI><output>Third item</output></LI>
67
+ </UL>
68
+ </dirac>
@@ -0,0 +1,10 @@
1
+ <dirac>
2
+ <subroutine name="greet">
3
+ <parameters select="@name"/>
4
+ <output>Hello, <variable name="name"/>!</output>
5
+ </subroutine>
6
+
7
+ <greet name="Alice"/>
8
+ <output>&#10;</output>
9
+ <greet name="Bob"/>
10
+ </dirac>
@@ -0,0 +1,38 @@
1
+ <!-- Recipe Generator - Chained LLM calls -->
2
+ <dirac>
3
+ <defvar name="ingredients" value="chicken, rice, tomatoes, garlic" />
4
+
5
+ <output>Available ingredients: ${ingredients}&#10;&#10;</output>
6
+
7
+ <!-- Step 1: Generate a dish name -->
8
+ <output>Step 1: Coming up with a dish...&#10;</output>
9
+ <LLM output="dishName" maxTokens="50">
10
+ Given these ingredients: ${ingredients}
11
+ Suggest ONE dish name (just the name, nothing else).
12
+ </LLM>
13
+ <output>Dish: ${dishName}&#10;&#10;</output>
14
+
15
+ <!-- Step 2: Create the recipe using the dish name -->
16
+ <output>Step 2: Creating recipe for ${dishName}...&#10;</output>
17
+ <LLM output="recipe" maxTokens="400">
18
+ Create a simple recipe for "${dishName}" using: ${ingredients}
19
+
20
+ Format:
21
+ Ingredients:
22
+ - list items
23
+
24
+ Instructions:
25
+ 1. numbered steps
26
+
27
+ Keep it brief and practical.
28
+ </LLM>
29
+ <output>&#10;${recipe}&#10;&#10;</output>
30
+
31
+ <!-- Step 3: Estimate cooking time -->
32
+ <output>Step 3: Estimating time...&#10;</output>
33
+ <LLM output="cookTime" maxTokens="50" context="recipe">
34
+ Based on this recipe, what's the total cooking time?
35
+ Answer with just a number and unit (e.g., "45 minutes").
36
+ </LLM>
37
+ <output>Total time: ${cookTime}&#10;</output>
38
+ </dirac>
@@ -0,0 +1,44 @@
1
+ <!-- Recursive LLM-Dirac Interleaving (LISP Style) -->
2
+ <dirac>
3
+ <output>Recursive Execution Demo&#10;&#10;</output>
4
+
5
+ <!-- Define subroutines that can be called by LLM -->
6
+ <subroutine name="GET_FILE_COUNT">
7
+ <eval name="count">
8
+ return fs.readdirSync('examples').filter(f => f.endsWith('.di')).length;
9
+ </eval>
10
+ <output>File count: ${count}&#10;</output>
11
+ </subroutine>
12
+
13
+ <subroutine name="GET_FILE_NAMES">
14
+ <eval name="names">
15
+ return fs.readdirSync('examples')
16
+ .filter(f => f.endsWith('.di'))
17
+ .slice(0, 3)
18
+ .join(', ');
19
+ </eval>
20
+ <output>Sample files: ${names}&#10;</output>
21
+ </subroutine>
22
+
23
+ <subroutine name="ANALYZE_DEEPER">
24
+ <output>Deep analysis requested...&#10;</output>
25
+ <!-- This subroutine itself calls an LLM! Recursion! -->
26
+ <LLM execute="true" maxTokens="80">
27
+ Return XML: &lt;dirac&gt;&lt;output&gt;Analysis complete!&#10;&lt;/output&gt;&lt;/dirac&gt;
28
+ </LLM>
29
+ </subroutine>
30
+
31
+ <!-- Level 1: User calls LLM -->
32
+ <output>Level 1: Asking LLM to analyze...&#10;</output>
33
+ <LLM execute="true" maxTokens="150">
34
+ Return ONLY XML calling these subroutines:
35
+ &lt;dirac&gt;
36
+ &lt;output&gt;Starting analysis...&#10;&lt;/output&gt;
37
+ &lt;GET_FILE_COUNT /&gt;
38
+ &lt;GET_FILE_NAMES /&gt;
39
+ &lt;ANALYZE_DEEPER /&gt;
40
+ &lt;/dirac&gt;
41
+ </LLM>
42
+
43
+ <output>&#10;All levels complete!&#10;</output>
44
+ </dirac>
@@ -0,0 +1,152 @@
1
+ # dirac-string
2
+
3
+ String manipulation library for Dirac.
4
+
5
+ ![npm version](https://img.shields.io/npm/v/dirac-string)
6
+ ![license](https://img.shields.io/npm/l/dirac-string)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install dirac-string
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```xml
17
+ <dirac>
18
+ <import src="./node_modules/dirac-string/lib/index.di"/>
19
+
20
+ <UPPERCASE text="hello world"/>
21
+ <!-- Outputs: HELLO WORLD -->
22
+
23
+ <LOWERCASE text="HELLO WORLD"/>
24
+ <!-- Outputs: hello world -->
25
+
26
+ <SUBSTRING text="Hello World" start="0" end="5"/>
27
+ <!-- Outputs: Hello -->
28
+ </dirac>
29
+ ```
30
+
31
+ ## API Reference
32
+
33
+ ### UPPERCASE
34
+ Convert text to uppercase.
35
+
36
+ **Attributes:**
37
+ - `text` (string, required) - Text to convert
38
+
39
+ **Example:**
40
+ ```xml
41
+ <UPPERCASE text="hello"/>
42
+ <!-- Output: HELLO -->
43
+ ```
44
+
45
+ ### LOWERCASE
46
+ Convert text to lowercase.
47
+
48
+ **Attributes:**
49
+ - `text` (string, required) - Text to convert
50
+
51
+ **Example:**
52
+ ```xml
53
+ <LOWERCASE text="WORLD"/>
54
+ <!-- Output: world -->
55
+ ```
56
+
57
+ ### TRIM
58
+ Remove leading and trailing whitespace.
59
+
60
+ **Attributes:**
61
+ - `text` (string, required) - Text to trim
62
+
63
+ **Example:**
64
+ ```xml
65
+ <TRIM text=" hello "/>
66
+ <!-- Output: hello -->
67
+ ```
68
+
69
+ ### SUBSTRING
70
+ Extract a substring.
71
+
72
+ **Attributes:**
73
+ - `text` (string, required) - Source text
74
+ - `start` (number, required) - Start index (0-based)
75
+ - `end` (number, optional) - End index (exclusive)
76
+
77
+ **Example:**
78
+ ```xml
79
+ <SUBSTRING text="Hello World" start="6" end="11"/>
80
+ <!-- Output: World -->
81
+ ```
82
+
83
+ ### REPLACE
84
+ Replace all occurrences of a pattern.
85
+
86
+ **Attributes:**
87
+ - `text` (string, required) - Source text
88
+ - `find` (string, required) - Pattern to find (regex)
89
+ - `replace` (string, required) - Replacement text
90
+
91
+ **Example:**
92
+ ```xml
93
+ <REPLACE text="Hello World" find="World" replace="Dirac"/>
94
+ <!-- Output: Hello Dirac -->
95
+ ```
96
+
97
+ ### SPLIT
98
+ Split text into array.
99
+
100
+ **Attributes:**
101
+ - `text` (string, required) - Text to split
102
+ - `delimiter` (string, optional) - Delimiter (default: ",")
103
+
104
+ **Example:**
105
+ ```xml
106
+ <SPLIT text="a,b,c" delimiter=","/>
107
+ <!-- Output: ["a","b","c"] -->
108
+ ```
109
+
110
+ ### LENGTH
111
+ Get string length.
112
+
113
+ **Attributes:**
114
+ - `text` (string, required) - Text to measure
115
+
116
+ **Example:**
117
+ ```xml
118
+ <LENGTH text="Hello"/>
119
+ <!-- Output: 5 -->
120
+ ```
121
+
122
+ ## Development
123
+
124
+ ```bash
125
+ # Clone repository
126
+ git clone https://github.com/dirac-lang/dirac-string
127
+ cd dirac-string
128
+
129
+ # Run examples
130
+ dirac examples/demo.di
131
+
132
+ # Run tests
133
+ npm test
134
+ ```
135
+
136
+ ## Contributing
137
+
138
+ Contributions welcome! Please:
139
+ 1. Fork the repository
140
+ 2. Create a feature branch
141
+ 3. Add tests for new functionality
142
+ 4. Submit a pull request
143
+
144
+ ## License
145
+
146
+ MIT © Dirac Community
147
+
148
+ ## Links
149
+
150
+ - [Dirac Language](https://github.com/wangzhi63/dirac)
151
+ - [Report Issues](https://github.com/dirac-lang/dirac-string/issues)
152
+ - [All Dirac Libraries](https://github.com/topics/dirac-library)
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env dirac
2
+ <dirac>
3
+ <import src="../lib/index.di"/>
4
+
5
+ <output>String Library Demo&#10;&#10;</output>
6
+
7
+ <output>1. STR_UPPERCASE: </output>
8
+ <STR_UPPERCASE text="hello world"/>
9
+ <output>&#10;</output>
10
+
11
+ <output>2. STR_LOWERCASE: </output>
12
+ <STR_LOWERCASE text="HELLO WORLD"/>
13
+ <output>&#10;</output>
14
+
15
+ <output>3. STR_TRIM: </output>
16
+ <STR_TRIM text=" spaces "/>
17
+ <output>&#10;</output>
18
+
19
+ <output>4. STR_SUBSTRING (0,5): </output>
20
+ <STR_SUBSTRING text="Hello World" start="0" end="5"/>
21
+ <output>&#10;</output>
22
+
23
+ <output>5. STR_REPLACE: </output>
24
+ <STR_REPLACE text="Hello World" find="World" replace="Dirac"/>
25
+ <output>&#10;</output>
26
+
27
+ <output>6. STR_SPLIT: </output>
28
+ <STR_SPLIT text="apple,banana,cherry" delimiter=","/>
29
+ <output>&#10;</output>
30
+
31
+ <output>7. STR_LENGTH: </output>
32
+ <STR_LENGTH text="Hello"/>
33
+ <output>&#10;</output>
34
+ </dirac>