Skip to content

Commit cf7e539

Browse files
authored
Merge pull request #1045 from Gijsreyn/add-stringdate-function-docs
Add endsWith(), startsWith(), uniqueString(), and utcNow() docs
2 parents 7a0bda5 + 5fb13c3 commit cf7e539

File tree

4 files changed

+732
-0
lines changed

4 files changed

+732
-0
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
description: Reference for the 'endsWith' DSC configuration document function
3+
ms.date: 08/12/2025
4+
ms.topic: reference
5+
title: endsWith
6+
---
7+
8+
# endsWith
9+
10+
## Synopsis
11+
12+
Determines whether a string ends with the specified suffix.
13+
14+
## Syntax
15+
16+
```Syntax
17+
endsWith(<string>, <suffix>)
18+
```
19+
20+
## Description
21+
22+
The `endsWith()` function returns `true` if the first string ends with the
23+
specified suffix. Comparison is case-sensitive. Use it for conditional logic in
24+
configuration documents such as matching file extensions, environment name
25+
suffixes, or resource identifiers.
26+
27+
## Examples
28+
29+
### Example 1 - Check a file extension
30+
31+
The following example checks if a specified filename ends with `.log`.
32+
33+
```yaml
34+
# endswith.example.1.dsc.config.yaml
35+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
36+
parameters:
37+
fileName:
38+
type: string
39+
defaultValue: application.log
40+
resources:
41+
- name: Check file extension
42+
type: Microsoft.DSC.Debug/Echo
43+
properties:
44+
output:
45+
isLog: "[endsWith(parameters('fileName'), '.log')]"
46+
```
47+
48+
```bash
49+
dsc config get --file endswith.example.1.dsc.config.yaml
50+
```
51+
52+
```yaml
53+
results:
54+
- name: Check file extension
55+
type: Microsoft.DSC.Debug/Echo
56+
result:
57+
actualState:
58+
output:
59+
isLog: true
60+
messages: []
61+
hadErrors: false
62+
```
63+
64+
### Example 2 - Conditional environment handling
65+
66+
The following example uses `endsWith()` to build a message when an environment
67+
name ends with `-prod`.
68+
69+
```yaml
70+
# endswith.example.2.dsc.config.yaml
71+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
72+
parameters:
73+
environment:
74+
type: string
75+
defaultValue: web-prod
76+
resources:
77+
- name: Environment classification
78+
type: Microsoft.DSC.Debug/Echo
79+
properties:
80+
output:
81+
classification: "[if(endsWith(parameters('environment'), '-prod'), 'Production', 'Non-production')]"
82+
```
83+
84+
```bash
85+
dsc config get --file endswith.example.2.dsc.config.yaml
86+
```
87+
88+
```yaml
89+
results:
90+
- name: Environment classification
91+
type: Microsoft.DSC.Debug/Echo
92+
result:
93+
actualState:
94+
output:
95+
classification: Production
96+
messages: []
97+
hadErrors: false
98+
```
99+
100+
### Example 3 - Filter resource identifiers
101+
102+
The following example shows checking multiple suffixes by combining conditions.
103+
104+
```yaml
105+
# endswith.example.3.dsc.config.yaml
106+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
107+
parameters:
108+
resourceId:
109+
type: string
110+
defaultValue: storage-westus-01
111+
resources:
112+
- name: Identify resource segment
113+
type: Microsoft.DSC.Debug/Echo
114+
properties:
115+
output:
116+
isRegional: "[endsWith(parameters('resourceId'), '-01')]"
117+
endsWithWest: "[endsWith(parameters('resourceId'), 'westus-01')]"
118+
endsWithEast: "[endsWith(parameters('resourceId'), 'eastus-01')]"
119+
```
120+
121+
```bash
122+
dsc config get --file endswith.example.3.dsc.config.yaml
123+
```
124+
125+
```yaml
126+
results:
127+
- name: Identify resource segment
128+
type: Microsoft.DSC.Debug/Echo
129+
result:
130+
actualState:
131+
output:
132+
isRegional: true
133+
endsWithWest: true
134+
endsWithEast: false
135+
messages: []
136+
hadErrors: false
137+
```
138+
139+
## Parameters
140+
141+
### string
142+
143+
The input string to evaluate.
144+
145+
```yaml
146+
Type: string
147+
Required: true
148+
Position: 1
149+
```
150+
151+
### suffix
152+
153+
The suffix string to test for.
154+
155+
```yaml
156+
Type: string
157+
Required: true
158+
Position: 2
159+
```
160+
161+
## Output
162+
163+
The `endsWith()` function returns a boolean value indicating whether the input
164+
string ends with the specified suffix.
165+
166+
```yaml
167+
Type: bool
168+
```
169+
170+
## Related functions
171+
172+
- [`startsWith()`][00] - Determines whether a string starts with a prefix
173+
- [`concat()`][01] - Concatenates strings together
174+
- [`if()`][02] - Returns values based on a condition
175+
- [`string()`][03] - Converts values to strings
176+
177+
<!-- Link reference definitions -->
178+
[00]: ./startsWith.md
179+
[01]: ./concat.md
180+
[02]: ./if.md
181+
[03]: ./string.md
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
description: Reference for the 'startsWith' DSC configuration document function
3+
ms.date: 08/12/2025
4+
ms.topic: reference
5+
title: startsWith
6+
---
7+
8+
# startsWith
9+
10+
## Synopsis
11+
12+
Determines whether a string starts with the specified prefix.
13+
14+
## Syntax
15+
16+
```Syntax
17+
startsWith(<string>, <prefix>)
18+
```
19+
20+
## Description
21+
22+
The `startsWith()` function returns `true` if the first string starts with the
23+
specified prefix. Comparison is case-sensitive. Use it for conditional logic in
24+
configuration documents such as grouping resource names, validating identifiers,
25+
or routing operations based on naming conventions.
26+
27+
## Examples
28+
29+
### Example 1 - Validate resource naming convention
30+
31+
The following example checks if a resource name follows a standard prefix.
32+
33+
```yaml
34+
# startswith.example.1.dsc.config.yaml
35+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
36+
parameters:
37+
resourceName:
38+
type: string
39+
defaultValue: svc-api-west
40+
resources:
41+
- name: Resource naming check
42+
type: Microsoft.DSC.Debug/Echo
43+
properties:
44+
output:
45+
hasSvcPrefix: "[startsWith(parameters('resourceName'), 'svc-')]"
46+
```
47+
48+
```bash
49+
dsc config get --file startswith.example.1.dsc.config.yaml
50+
```
51+
52+
```yaml
53+
results:
54+
- name: Resource naming check
55+
type: Microsoft.DSC.Debug/Echo
56+
result:
57+
actualState:
58+
output:
59+
hasSvcPrefix: true
60+
messages: []
61+
hadErrors: false
62+
```
63+
64+
### Example 2 - Conditional routing
65+
66+
The following example shows using `startsWith()` with `if()` to categorize a
67+
service by its name prefix.
68+
69+
```yaml
70+
# startswith.example.2.dsc.config.yaml
71+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
72+
parameters:
73+
serviceName:
74+
type: string
75+
defaultValue: api-orders
76+
resources:
77+
- name: Service classification
78+
type: Microsoft.DSC.Debug/Echo
79+
properties:
80+
output:
81+
classification: "[if(startsWith(parameters('serviceName'), 'api-'), 'API Service', 'Other Service')]"
82+
```
83+
84+
```bash
85+
dsc config get --file startswith.example.2.dsc.config.yaml
86+
```
87+
88+
```yaml
89+
results:
90+
- name: Service classification
91+
type: Microsoft.DSC.Debug/Echo
92+
result:
93+
actualState:
94+
output:
95+
classification: API Service
96+
messages: []
97+
hadErrors: false
98+
```
99+
100+
### Example 3 - Multi-prefix evaluation
101+
102+
The following example evaluates multiple possible prefixes.
103+
104+
```yaml
105+
# startswith.example.3.dsc.config.yaml
106+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
107+
parameters:
108+
name:
109+
type: string
110+
defaultValue: db-primary-01
111+
resources:
112+
- name: Prefix grouping
113+
type: Microsoft.DSC.Debug/Echo
114+
properties:
115+
output:
116+
isDb: "[startsWith(parameters('name'), 'db-')]"
117+
isApi: "[startsWith(parameters('name'), 'api-')]"
118+
isCache: "[startsWith(parameters('name'), 'cache-')]"
119+
```
120+
121+
```bash
122+
dsc config get --file startswith.example.3.dsc.config.yaml
123+
```
124+
125+
```yaml
126+
results:
127+
- name: Prefix grouping
128+
type: Microsoft.DSC.Debug/Echo
129+
result:
130+
actualState:
131+
output:
132+
isDb: true
133+
isApi: false
134+
isCache: false
135+
messages: []
136+
hadErrors: false
137+
```
138+
139+
## Parameters
140+
141+
### string
142+
143+
The input string to evaluate.
144+
145+
```yaml
146+
Type: string
147+
Required: true
148+
Position: 1
149+
```
150+
151+
### prefix
152+
153+
The prefix string to test for.
154+
155+
```yaml
156+
Type: string
157+
Required: true
158+
Position: 2
159+
```
160+
161+
## Output
162+
163+
The `startsWith()` function returns a boolean value indicating whether the
164+
input string starts with the specified prefix.
165+
166+
```yaml
167+
Type: bool
168+
```
169+
170+
## Related functions
171+
172+
- [`endsWith()`][00] - Determines whether a string ends with a suffix
173+
- [`concat()`][01] - Concatenates strings together
174+
- [`if()`][02] - Returns values based on a condition
175+
- [`string()`][03] - Converts values to strings
176+
177+
<!-- Link reference definitions -->
178+
[00]: ./endsWith.md
179+
[01]: ./concat.md
180+
[02]: ./if.md
181+
[03]: ./string.md

0 commit comments

Comments
 (0)