@everyonesoftware/common 1.0.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.
- package/.c8rc.json +12 -0
- package/.github/workflows/publish.yml +38 -0
- package/.mocharc.json +9 -0
- package/README.md +9 -0
- package/package.json +36 -0
- package/sources/assertMessageParameters.ts +22 -0
- package/sources/asyncIterator.ts +437 -0
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
- package/sources/asyncResult.ts +95 -0
- package/sources/basicDisposable.ts +57 -0
- package/sources/byteList.ts +202 -0
- package/sources/byteListStream.ts +121 -0
- package/sources/byteReadStream.ts +24 -0
- package/sources/byteWriteStream.ts +16 -0
- package/sources/bytes.ts +25 -0
- package/sources/characterList.ts +195 -0
- package/sources/characterListStream.ts +151 -0
- package/sources/characterReadStream.ts +81 -0
- package/sources/characterReadStreamIterator.ts +128 -0
- package/sources/characterWriteStream.ts +45 -0
- package/sources/commandLineParameter.ts +45 -0
- package/sources/commandLineParameters.ts +21 -0
- package/sources/comparable.ts +144 -0
- package/sources/comparer.ts +133 -0
- package/sources/comparison.ts +20 -0
- package/sources/concatenateIterable.ts +119 -0
- package/sources/concatenateIterator.ts +165 -0
- package/sources/condition.ts +329 -0
- package/sources/currentProcess.ts +158 -0
- package/sources/dateTime.ts +130 -0
- package/sources/depthFirstSearch.ts +230 -0
- package/sources/disposable.ts +31 -0
- package/sources/emptyError.ts +10 -0
- package/sources/english.ts +45 -0
- package/sources/equalFunctions.ts +123 -0
- package/sources/fetchHttpClient.ts +89 -0
- package/sources/fetchHttpResponse.ts +106 -0
- package/sources/flatMapIterable.ts +104 -0
- package/sources/flatMapIterator.ts +152 -0
- package/sources/generator.ts +251 -0
- package/sources/httpClient.ts +36 -0
- package/sources/httpHeader.ts +37 -0
- package/sources/httpHeaders.ts +216 -0
- package/sources/httpIncomingRequest.ts +30 -0
- package/sources/httpIncomingResponse.ts +19 -0
- package/sources/httpMethod.ts +164 -0
- package/sources/httpOutgoingRequest.ts +119 -0
- package/sources/httpOutgoingResponse.ts +113 -0
- package/sources/httpServer.ts +34 -0
- package/sources/inMemoryCharacterWriteStream.ts +78 -0
- package/sources/index.ts +101 -0
- package/sources/iterable.ts +345 -0
- package/sources/iterator.ts +481 -0
- package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
- package/sources/javascript.ts +59 -0
- package/sources/javascriptArrayList.ts +175 -0
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
- package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
- package/sources/javascriptMapMap.ts +143 -0
- package/sources/javascriptSetSet.ts +134 -0
- package/sources/list.ts +330 -0
- package/sources/listQueue.ts +62 -0
- package/sources/listStack.ts +62 -0
- package/sources/luxonDateTime.ts +109 -0
- package/sources/map.ts +302 -0
- package/sources/mapAsyncIterator.ts +141 -0
- package/sources/mapIterable.ts +105 -0
- package/sources/mapIterator.ts +145 -0
- package/sources/mutableCondition.ts +451 -0
- package/sources/mutableHttpHeaders.ts +204 -0
- package/sources/mutableMap.ts +292 -0
- package/sources/network.ts +18 -0
- package/sources/node.ts +37 -0
- package/sources/nodeJSCharacterWriteStream.ts +42 -0
- package/sources/nodeJSHttpIncomingRequest.ts +132 -0
- package/sources/nodeJSHttpServer.ts +134 -0
- package/sources/notFoundError.ts +12 -0
- package/sources/postCondition.ts +284 -0
- package/sources/postConditionError.ts +12 -0
- package/sources/preCondition.ts +284 -0
- package/sources/preConditionError.ts +12 -0
- package/sources/promiseAsyncResult.ts +174 -0
- package/sources/property.ts +63 -0
- package/sources/queue.ts +49 -0
- package/sources/realNetwork.ts +28 -0
- package/sources/recreationDotGovClient.ts +259 -0
- package/sources/searchControl.ts +42 -0
- package/sources/set.ts +244 -0
- package/sources/skipAsyncIterator.ts +145 -0
- package/sources/skipIterator.ts +155 -0
- package/sources/stack.ts +48 -0
- package/sources/stringComparer.ts +33 -0
- package/sources/stringIterator.ts +149 -0
- package/sources/strings.ts +322 -0
- package/sources/syncResult.ts +300 -0
- package/sources/takeAsyncIterator.ts +141 -0
- package/sources/takeIterator.ts +151 -0
- package/sources/toStringFunctions.ts +185 -0
- package/sources/types.ts +371 -0
- package/sources/whereAsyncIterator.ts +143 -0
- package/sources/whereIterable.ts +108 -0
- package/sources/whereIterator.ts +157 -0
- package/sources/wonderlandTrailClient.ts +1503 -0
- package/tests/assertTest.ts +113 -0
- package/tests/assertTestTests.ts +75 -0
- package/tests/basicTestSkip.ts +51 -0
- package/tests/byteListStreamTests.ts +390 -0
- package/tests/byteListTests.ts +27 -0
- package/tests/bytesTests.ts +43 -0
- package/tests/characterListStreamTests.ts +391 -0
- package/tests/characterListTests.ts +250 -0
- package/tests/characterWriteStreamTests.ts +12 -0
- package/tests/comparerTests.ts +92 -0
- package/tests/conditionTests.ts +877 -0
- package/tests/consoleTestRunner.ts +404 -0
- package/tests/consoleTestRunnerTests.ts +651 -0
- package/tests/dateTimeTests.ts +30 -0
- package/tests/depthFirstSearchTests.ts +106 -0
- package/tests/disposableTests.ts +121 -0
- package/tests/englishTests.ts +103 -0
- package/tests/equalFunctionsTests.ts +223 -0
- package/tests/failedTest.ts +43 -0
- package/tests/fetchHttpClientTests.ts +33 -0
- package/tests/generatorTests.ts +86 -0
- package/tests/httpClientTests.ts +18 -0
- package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
- package/tests/iterableTests.ts +141 -0
- package/tests/iteratorTests.ts +1086 -0
- package/tests/javascriptMapMapTests.ts +21 -0
- package/tests/listTests.ts +338 -0
- package/tests/mapIteratorTests.ts +55 -0
- package/tests/mapTests.ts +104 -0
- package/tests/mutableConditionTests.ts +273 -0
- package/tests/mutableMapTests.ts +154 -0
- package/tests/nodeJSHttpServerTests.ts +75 -0
- package/tests/notFoundErrorTests.ts +24 -0
- package/tests/postConditionErrorTests.ts +24 -0
- package/tests/preConditionErrorTests.ts +24 -0
- package/tests/promiseAsyncResultTests.ts +688 -0
- package/tests/propertyTests.ts +63 -0
- package/tests/queueTests.ts +29 -0
- package/tests/recreationDotGovClientTests.ts +191 -0
- package/tests/setTests.ts +140 -0
- package/tests/skippedTest.ts +39 -0
- package/tests/stackTests.ts +66 -0
- package/tests/stringComparerTests.ts +60 -0
- package/tests/stringIteratorTests.ts +156 -0
- package/tests/stringsTests.ts +516 -0
- package/tests/syncResultTests.ts +1251 -0
- package/tests/test.ts +228 -0
- package/tests/testAction.ts +75 -0
- package/tests/testActionTests.ts +93 -0
- package/tests/testFailureTests.ts +12 -0
- package/tests/testRunner.ts +267 -0
- package/tests/testRunnerTests.ts +895 -0
- package/tests/testSkip.ts +34 -0
- package/tests/tests.ts +103 -0
- package/tests/toStringFunctionsTests.ts +55 -0
- package/tests/typesTests.ts +257 -0
- package/tests/whereIteratorTests.ts +77 -0
- package/tests/wonderlandTrailClientTests.ts +452 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Iterator } from "./iterator";
|
|
2
|
+
import { JavascriptIterable, JavascriptIterator } from "./javascript";
|
|
3
|
+
import { PreCondition } from "./preCondition";
|
|
4
|
+
import { SyncResult } from "./syncResult";
|
|
5
|
+
import { Type } from "./types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An {@link Iterator} that iterates over the characters in a {@link string}.
|
|
9
|
+
*/
|
|
10
|
+
export class StringIterator implements Iterator<string>
|
|
11
|
+
{
|
|
12
|
+
private readonly value: string;
|
|
13
|
+
private currentIndex: number;
|
|
14
|
+
private started: boolean;
|
|
15
|
+
|
|
16
|
+
private constructor(value: string)
|
|
17
|
+
{
|
|
18
|
+
this.value = value;
|
|
19
|
+
this.currentIndex = 0;
|
|
20
|
+
this.started = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static create(value: string): StringIterator
|
|
24
|
+
{
|
|
25
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
26
|
+
|
|
27
|
+
return new StringIterator(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public getCurrentIndex(): number
|
|
31
|
+
{
|
|
32
|
+
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
33
|
+
|
|
34
|
+
return this.currentIndex;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public next(): SyncResult<boolean>
|
|
38
|
+
{
|
|
39
|
+
return SyncResult.create(() =>
|
|
40
|
+
{
|
|
41
|
+
if (!this.hasStarted())
|
|
42
|
+
{
|
|
43
|
+
this.started = true;
|
|
44
|
+
}
|
|
45
|
+
else if (this.hasCurrent())
|
|
46
|
+
{
|
|
47
|
+
this.currentIndex++;
|
|
48
|
+
}
|
|
49
|
+
return this.hasCurrent();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public hasStarted(): boolean
|
|
54
|
+
{
|
|
55
|
+
return this.started;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public hasCurrent(): boolean
|
|
59
|
+
{
|
|
60
|
+
return this.hasStarted() && this.currentIndex < this.value.length;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getCurrent(): string
|
|
64
|
+
{
|
|
65
|
+
PreCondition.assertTrue(this.hasCurrent(), "this.hasCurrent()");
|
|
66
|
+
|
|
67
|
+
return this.value[this.currentIndex];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public start(): SyncResult<this>
|
|
71
|
+
{
|
|
72
|
+
return Iterator.start<string, this>(this);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public takeCurrent(): SyncResult<string>
|
|
76
|
+
{
|
|
77
|
+
return Iterator.takeCurrent(this);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public any(): SyncResult<boolean>
|
|
81
|
+
{
|
|
82
|
+
return Iterator.any(this);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public getCount(): SyncResult<number>
|
|
86
|
+
{
|
|
87
|
+
return Iterator.getCount(this);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public toArray(): SyncResult<string[]>
|
|
91
|
+
{
|
|
92
|
+
return Iterator.toArray(this);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public concatenate(...toConcatenate: JavascriptIterable<string>[]): Iterator<string>
|
|
96
|
+
{
|
|
97
|
+
return Iterator.concatenate(this, ...toConcatenate);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public map<TOutput>(mapping: (value: string) => (TOutput | SyncResult<TOutput>)): Iterator<TOutput>
|
|
101
|
+
{
|
|
102
|
+
return Iterator.map(this, mapping);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public flatMap<TOutput>(mapping: (value: string) => JavascriptIterable<TOutput>): Iterator<TOutput>
|
|
106
|
+
{
|
|
107
|
+
return Iterator.flatMap(this, mapping);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public first(): SyncResult<string>
|
|
111
|
+
{
|
|
112
|
+
return Iterator.first(this);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public last(): SyncResult<string>
|
|
116
|
+
{
|
|
117
|
+
return Iterator.last(this);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public where(condition: (value: string) => boolean): Iterator<string>
|
|
121
|
+
{
|
|
122
|
+
return Iterator.where(this, condition);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public whereInstanceOf<U extends string>(typeCheck: (value: string) => value is U): Iterator<U>
|
|
126
|
+
{
|
|
127
|
+
return Iterator.whereInstanceOf(this, typeCheck);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public whereInstanceOfType<U extends string>(type: Type<U>): Iterator<U>
|
|
131
|
+
{
|
|
132
|
+
return Iterator.whereInstanceOfType(this, type);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public take(maximumToTake: number): Iterator<string>
|
|
136
|
+
{
|
|
137
|
+
return Iterator.take(this, maximumToTake);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public skip(maximumToSkip: number): Iterator<string>
|
|
141
|
+
{
|
|
142
|
+
return Iterator.skip(this, maximumToSkip);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public [Symbol.iterator](): JavascriptIterator<string>
|
|
146
|
+
{
|
|
147
|
+
return Iterator[Symbol.iterator](this);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { JavascriptIterable } from "./javascript";
|
|
2
|
+
import { PreCondition } from "./preCondition";
|
|
3
|
+
import { isString } from "./types";
|
|
4
|
+
|
|
5
|
+
export function getLength(value: string | undefined | null): number
|
|
6
|
+
{
|
|
7
|
+
return value !== undefined && value !== null ? value.length : 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function toString(value: undefined | null | { toString(): string }): string
|
|
11
|
+
{
|
|
12
|
+
let result: string;
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
{
|
|
15
|
+
result = "undefined";
|
|
16
|
+
}
|
|
17
|
+
else if (value === null)
|
|
18
|
+
{
|
|
19
|
+
result = "null";
|
|
20
|
+
}
|
|
21
|
+
else
|
|
22
|
+
{
|
|
23
|
+
result = value.toString();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Join the provided values with the provided separator in between each value.
|
|
31
|
+
* @param separator The value to use to separate the individual values.
|
|
32
|
+
* @param values The values to join.
|
|
33
|
+
* @returns The joined {@link string}.
|
|
34
|
+
*/
|
|
35
|
+
export function join(separator: string, values: JavascriptIterable<string>): string;
|
|
36
|
+
export function join(parameters: { separator: string, values: JavascriptIterable<string> }): string;
|
|
37
|
+
export function join(separatorOrParameters: string | { separator: string, values: JavascriptIterable<string> }, values?: JavascriptIterable<string>): string
|
|
38
|
+
{
|
|
39
|
+
let separator: string;
|
|
40
|
+
if (isString(separatorOrParameters) || separatorOrParameters === undefined || separatorOrParameters === null)
|
|
41
|
+
{
|
|
42
|
+
separator = separatorOrParameters;
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
{
|
|
46
|
+
separator = separatorOrParameters.separator;
|
|
47
|
+
values = separatorOrParameters.values;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
PreCondition.assertNotUndefinedAndNotNull(separator, "separator");
|
|
51
|
+
PreCondition.assertNotUndefinedAndNotNull(values, "values");
|
|
52
|
+
|
|
53
|
+
return Array.from(values).join(separator);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function escape(value: string | undefined | null, dontEscape?: string[]): string;
|
|
57
|
+
export function escape(parameters: { value: string | undefined | null, dontEscape?: string[] }): string;
|
|
58
|
+
export function escape(valueOrParameters: string | undefined | null | { value: string | undefined | null, dontEscape?: string[] }, dontEscape?: string[]): string
|
|
59
|
+
{
|
|
60
|
+
let value: string | undefined | null;
|
|
61
|
+
if (isString(valueOrParameters) || valueOrParameters === undefined || valueOrParameters === null)
|
|
62
|
+
{
|
|
63
|
+
value = valueOrParameters;
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
value = valueOrParameters.value;
|
|
68
|
+
dontEscape = valueOrParameters.dontEscape;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let result: string;
|
|
72
|
+
if (value === undefined)
|
|
73
|
+
{
|
|
74
|
+
result = "undefined";
|
|
75
|
+
}
|
|
76
|
+
else if (value === null)
|
|
77
|
+
{
|
|
78
|
+
result = "null";
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
if (!dontEscape)
|
|
83
|
+
{
|
|
84
|
+
dontEscape = [];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
result = "";
|
|
88
|
+
for (const character of value)
|
|
89
|
+
{
|
|
90
|
+
if (dontEscape.includes(character))
|
|
91
|
+
{
|
|
92
|
+
result += character;
|
|
93
|
+
}
|
|
94
|
+
else
|
|
95
|
+
{
|
|
96
|
+
switch (character)
|
|
97
|
+
{
|
|
98
|
+
case "\n":
|
|
99
|
+
result += "\\n";
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case "\r":
|
|
103
|
+
result += "\\r";
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
case "\t":
|
|
107
|
+
result += "\\t";
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
case "\'":
|
|
111
|
+
result += "\\\'";
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
case "\"":
|
|
115
|
+
result += "\\\"";
|
|
116
|
+
break;
|
|
117
|
+
|
|
118
|
+
default:
|
|
119
|
+
result += character;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get a version of the provided value that is quoted with the provided quote.
|
|
130
|
+
* @param value The value to quote.
|
|
131
|
+
* @param quote The quotes to surround the provided value with.
|
|
132
|
+
*/
|
|
133
|
+
export function quote(value: string | undefined | null, quote?: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Get a version of the provided value that is quoted with the provided quote.
|
|
136
|
+
* @param parameters The parameters to use to invoke this function.
|
|
137
|
+
*/
|
|
138
|
+
export function quote(parameters: { value: string | undefined | null, quote?: string }): string;
|
|
139
|
+
export function quote(valueOrParameters: string | undefined | null | { value: string | undefined | null, quote?: string }, quote?: string): string
|
|
140
|
+
{
|
|
141
|
+
let value: string | undefined | null;
|
|
142
|
+
if (isString(valueOrParameters) || valueOrParameters === undefined || valueOrParameters === null)
|
|
143
|
+
{
|
|
144
|
+
value = valueOrParameters;
|
|
145
|
+
}
|
|
146
|
+
else
|
|
147
|
+
{
|
|
148
|
+
value = valueOrParameters.value;
|
|
149
|
+
quote = valueOrParameters.quote;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let result: string;
|
|
153
|
+
if (value === undefined)
|
|
154
|
+
{
|
|
155
|
+
result = "undefined";
|
|
156
|
+
}
|
|
157
|
+
else if (value === null)
|
|
158
|
+
{
|
|
159
|
+
result = "null";
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
{
|
|
163
|
+
if (quote === undefined)
|
|
164
|
+
{
|
|
165
|
+
quote = "\"";
|
|
166
|
+
}
|
|
167
|
+
result = `${quote}${value}${quote}`;
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get a version of the provided value where the characters are escaped and quoted.
|
|
174
|
+
* @param value The value to escape and quote.
|
|
175
|
+
* @param quoteString The quote to surround the value with.
|
|
176
|
+
* @param dontEscape The characters to not escape.
|
|
177
|
+
*/
|
|
178
|
+
export function escapeAndQuote(value: string | undefined | null, quoteString?: string, dontEscape?: string[]): string;
|
|
179
|
+
export function escapeAndQuote(parameters: { value: string | undefined | null, quoteString?: string, dontEscape?: string[] }): string;
|
|
180
|
+
export function escapeAndQuote(valueOrParameters: string | undefined | null | { value: string | undefined | null, quoteString?: string, dontEscape?: string[] }, quoteString?: string, dontEscape?: string[]): string
|
|
181
|
+
{
|
|
182
|
+
let value: string | undefined | null;
|
|
183
|
+
if (isString(valueOrParameters) || valueOrParameters === undefined || valueOrParameters === null)
|
|
184
|
+
{
|
|
185
|
+
value = valueOrParameters;
|
|
186
|
+
}
|
|
187
|
+
else
|
|
188
|
+
{
|
|
189
|
+
value = valueOrParameters.value;
|
|
190
|
+
quoteString = valueOrParameters.quoteString;
|
|
191
|
+
dontEscape = valueOrParameters.dontEscape;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let result: string;
|
|
195
|
+
if (value === undefined)
|
|
196
|
+
{
|
|
197
|
+
result = "undefined";
|
|
198
|
+
}
|
|
199
|
+
else if (value === null)
|
|
200
|
+
{
|
|
201
|
+
result = "null";
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
{
|
|
205
|
+
result = escape(value, dontEscape);
|
|
206
|
+
result = quote(result, quoteString);
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Get whether the provided value only contains whitespace characters.
|
|
213
|
+
* @param value The value to check.
|
|
214
|
+
*/
|
|
215
|
+
export function isWhitespace(value: string): boolean
|
|
216
|
+
{
|
|
217
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
218
|
+
PreCondition.assertSame(1, value.length, "value.length");
|
|
219
|
+
|
|
220
|
+
let result: boolean = true;
|
|
221
|
+
switch (value[0])
|
|
222
|
+
{
|
|
223
|
+
case " ":
|
|
224
|
+
case "\r":
|
|
225
|
+
case "\n":
|
|
226
|
+
case "\t":
|
|
227
|
+
result = true;
|
|
228
|
+
break;
|
|
229
|
+
|
|
230
|
+
default:
|
|
231
|
+
result = false;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Get whether the provided value only contains letters.
|
|
239
|
+
* @param value The value to check.
|
|
240
|
+
*/
|
|
241
|
+
export function isLetter(value: string): boolean
|
|
242
|
+
{
|
|
243
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
244
|
+
PreCondition.assertSame(1, value.length, "value.length");
|
|
245
|
+
|
|
246
|
+
const character: string = value[0];
|
|
247
|
+
let result: boolean = false;
|
|
248
|
+
if ("A" <= character)
|
|
249
|
+
{
|
|
250
|
+
result = (character <= "Z");
|
|
251
|
+
if (!result && "a" <= character)
|
|
252
|
+
{
|
|
253
|
+
result = (character <= "z");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Get whether the provided value only contains letters.
|
|
261
|
+
* @param value The value to check.
|
|
262
|
+
*/
|
|
263
|
+
export function isLowercasedLetter(value: string): boolean
|
|
264
|
+
{
|
|
265
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
266
|
+
PreCondition.assertSame(1, value.length, "value.length");
|
|
267
|
+
|
|
268
|
+
const character: string = value[0];
|
|
269
|
+
return ("a" <= character && character <= "z");
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get whether the provided value only contains letters.
|
|
274
|
+
* @param value The value to check.
|
|
275
|
+
*/
|
|
276
|
+
export function isUppercasedLetter(value: string): boolean
|
|
277
|
+
{
|
|
278
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
279
|
+
PreCondition.assertSame(1, value.length, "value.length");
|
|
280
|
+
|
|
281
|
+
const character: string = value[0];
|
|
282
|
+
return ("A" <= character && character <= "Z");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get whether the provided value only contains digits.
|
|
287
|
+
* @param value The value to check.
|
|
288
|
+
*/
|
|
289
|
+
export function isDigit(value: string): boolean
|
|
290
|
+
{
|
|
291
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
292
|
+
PreCondition.assertSame(1, value.length, "value.length");
|
|
293
|
+
|
|
294
|
+
const character: string = value[0];
|
|
295
|
+
return ("0" <= character && character <= "9");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Get whether the provided value only contains letters and digits.
|
|
300
|
+
* @param value The value to check.
|
|
301
|
+
*/
|
|
302
|
+
export function isLetterOrDigit(value: string): boolean
|
|
303
|
+
{
|
|
304
|
+
PreCondition.assertNotUndefinedAndNotNull(value, "value");
|
|
305
|
+
PreCondition.assertSame(1, value.length, "value.length");
|
|
306
|
+
|
|
307
|
+
const character: string = value[0];
|
|
308
|
+
let result: boolean = false;
|
|
309
|
+
if ("0" <= character)
|
|
310
|
+
{
|
|
311
|
+
result = (character <= "9");
|
|
312
|
+
if (!result && "A" <= character)
|
|
313
|
+
{
|
|
314
|
+
result = (character <= "Z");
|
|
315
|
+
if (!result && "a" <= character)
|
|
316
|
+
{
|
|
317
|
+
result = (character <= "z");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|