unocab 0.8.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/LICENSE +21 -0
- package/README.md +108 -0
- package/esm/_dnt.shims.d.ts +4 -0
- package/esm/_dnt.shims.js +62 -0
- package/esm/_dnt.test_shims.d.ts +7 -0
- package/esm/deps/deno.land/std@0.190.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.190.0/testing/_diff.d.ts +26 -0
- package/esm/deps/deno.land/std@0.190.0/testing/_format.d.ts +1 -0
- package/esm/deps/deno.land/std@0.190.0/testing/asserts.d.ts +284 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/ZodError.d.ts +163 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/ZodError.js +148 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/errors.d.ts +5 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/errors.js +9 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/external.d.ts +6 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/external.js +6 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.d.ts +8 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.js +1 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.d.ts +9 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.js +5 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.d.ts +78 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.js +104 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.d.ts +8 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.js +1 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.d.ts +2 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.js +1 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/util.d.ts +68 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/helpers/util.js +138 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/index.d.ts +4 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/index.js +4 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/locales/en.d.ts +3 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/locales/en.js +127 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/mod.d.ts +1 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/mod.js +1 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/types.d.ts +965 -0
- package/esm/deps/deno.land/x/zod@v3.21.4/types.js +3689 -0
- package/esm/errors.d.ts +72 -0
- package/esm/errors.js +39 -0
- package/esm/game.d.ts +868 -0
- package/esm/game.js +868 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.js +3 -0
- package/esm/package.json +3 -0
- package/esm/tests/basic-tests.d.ts +8 -0
- package/esm/tests/draw-tests.d.ts +8 -0
- package/esm/tests/non-specific-tests.test.d.ts +1 -0
- package/esm/tests/rule-violation-tests.d.ts +8 -0
- package/esm/tests/specific-tests.test.d.ts +1 -0
- package/esm/tests/test-utils.d.ts +91 -0
- package/esm/tests/turn-tests.d.ts +8 -0
- package/esm/types.d.ts +2280 -0
- package/esm/types.js +152 -0
- package/esm/utils.d.ts +19 -0
- package/esm/utils.js +44 -0
- package/package.json +32 -0
- package/script/_dnt.shims.d.ts +4 -0
- package/script/_dnt.shims.js +66 -0
- package/script/_dnt.test_shims.d.ts +7 -0
- package/script/deps/deno.land/std@0.190.0/fmt/colors.d.ts +270 -0
- package/script/deps/deno.land/std@0.190.0/testing/_diff.d.ts +26 -0
- package/script/deps/deno.land/std@0.190.0/testing/_format.d.ts +1 -0
- package/script/deps/deno.land/std@0.190.0/testing/asserts.d.ts +284 -0
- package/script/deps/deno.land/x/zod@v3.21.4/ZodError.d.ts +163 -0
- package/script/deps/deno.land/x/zod@v3.21.4/ZodError.js +152 -0
- package/script/deps/deno.land/x/zod@v3.21.4/errors.d.ts +5 -0
- package/script/deps/deno.land/x/zod@v3.21.4/errors.js +17 -0
- package/script/deps/deno.land/x/zod@v3.21.4/external.d.ts +6 -0
- package/script/deps/deno.land/x/zod@v3.21.4/external.js +22 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.d.ts +8 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/enumUtil.js +2 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.d.ts +9 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/errorUtil.js +8 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.d.ts +78 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/parseUtil.js +119 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.d.ts +8 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/partialUtil.js +2 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.d.ts +2 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/typeAliases.js +2 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/util.d.ts +68 -0
- package/script/deps/deno.land/x/zod@v3.21.4/helpers/util.js +142 -0
- package/script/deps/deno.land/x/zod@v3.21.4/index.d.ts +4 -0
- package/script/deps/deno.land/x/zod@v3.21.4/index.js +33 -0
- package/script/deps/deno.land/x/zod@v3.21.4/locales/en.d.ts +3 -0
- package/script/deps/deno.land/x/zod@v3.21.4/locales/en.js +129 -0
- package/script/deps/deno.land/x/zod@v3.21.4/mod.d.ts +1 -0
- package/script/deps/deno.land/x/zod@v3.21.4/mod.js +17 -0
- package/script/deps/deno.land/x/zod@v3.21.4/types.d.ts +965 -0
- package/script/deps/deno.land/x/zod@v3.21.4/types.js +3739 -0
- package/script/errors.d.ts +72 -0
- package/script/errors.js +43 -0
- package/script/game.d.ts +868 -0
- package/script/game.js +895 -0
- package/script/mod.d.ts +3 -0
- package/script/mod.js +19 -0
- package/script/package.json +3 -0
- package/script/tests/basic-tests.d.ts +8 -0
- package/script/tests/draw-tests.d.ts +8 -0
- package/script/tests/non-specific-tests.test.d.ts +1 -0
- package/script/tests/rule-violation-tests.d.ts +8 -0
- package/script/tests/specific-tests.test.d.ts +1 -0
- package/script/tests/test-utils.d.ts +91 -0
- package/script/tests/turn-tests.d.ts +8 -0
- package/script/types.d.ts +2280 -0
- package/script/types.js +155 -0
- package/script/utils.d.ts +19 -0
- package/script/utils.js +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Udit Karode
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Unocab
|
|
2
|
+
|
|
3
|
+
Unocab is an UNO game engine. Usage is simple:
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
// On creation of a Game, an UNO deck of 108 cards is
|
|
7
|
+
// shuffled and assigned to `game.state.cache.deck`.
|
|
8
|
+
const game = new Game({
|
|
9
|
+
// Whether to stack +2s. If this is enabled, and
|
|
10
|
+
// say three +2s are played one after the other,
|
|
11
|
+
// the person to draw next will pick up 6 cards.
|
|
12
|
+
// This option is enabled by default.
|
|
13
|
+
stackPlusTwos: true,
|
|
14
|
+
|
|
15
|
+
// The initial seed determines all the random events
|
|
16
|
+
// of the game. Hence if you create two games with
|
|
17
|
+
// the same initial seed and the same number of players
|
|
18
|
+
// join the game at the same time, the shuffled deck and
|
|
19
|
+
// the hands of the players will be the same.
|
|
20
|
+
initialSeed: "unocab rocks!",
|
|
21
|
+
|
|
22
|
+
// Explained in the next README section.
|
|
23
|
+
shorthandMode: false,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// At the start of the game, the engine also plays the
|
|
27
|
+
// first card of the deck which is not a +4 or color
|
|
28
|
+
// switcher. After this point, players continue the
|
|
29
|
+
// game based on the type and color of this card.
|
|
30
|
+
|
|
31
|
+
// Whenever new players join, a hand of 7 cards is
|
|
32
|
+
// assigned to each of them. A hand is formed by
|
|
33
|
+
// drawing the top card of the deck 7 times. This
|
|
34
|
+
// is random, since the deck has been shuffled.
|
|
35
|
+
const [p1, p2] = ["player1", "player2"];
|
|
36
|
+
game.join(p1, p2);
|
|
37
|
+
|
|
38
|
+
// let's assume the first card was a Red 4, and p1 has
|
|
39
|
+
// a Red 6 and a +4.
|
|
40
|
+
game.play(p1, { type: "six", color: "red" });
|
|
41
|
+
|
|
42
|
+
game.draw(p2);
|
|
43
|
+
game.pass(p2);
|
|
44
|
+
|
|
45
|
+
game.play(p1, { type: "plus-four" });
|
|
46
|
+
game.switchColor(p1, "blue");
|
|
47
|
+
|
|
48
|
+
game.callBluff(p2);
|
|
49
|
+
|
|
50
|
+
// ... more moves
|
|
51
|
+
|
|
52
|
+
const end = game.hasEnded();
|
|
53
|
+
if (end) console.log(end.loser + " lost the game!");
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
# Full vs Shorthand mode
|
|
57
|
+
|
|
58
|
+
During creation of a `Game`, you can optionally pass in `shorthandMode: true`. In shorthand
|
|
59
|
+
mode, the engine only keeps as much information about the game as is needed for it to
|
|
60
|
+
function. Otherwise, **and by default**, **all** information about the game is kept in the events
|
|
61
|
+
array (`game.state.events`). This allows you to have a history of all the happenings in that
|
|
62
|
+
particular game, and also allows you to jump to an arbitrary point in the game. For example,
|
|
63
|
+
to undo a move, you could use `game.jumpToEventIndex(-2)`. This
|
|
64
|
+
function is not usable in shorthand mode, and the events array will only keep 5 events at most.
|
|
65
|
+
|
|
66
|
+
**TLDR**: Use shorthand mode if you don't want to use `jumpToEventIndex` or keep the entire game history.
|
|
67
|
+
|
|
68
|
+
# Serialising and Deserialising
|
|
69
|
+
|
|
70
|
+
A game can be serialised into JSON using `game.serialise()`, and cloned using `game.clone()`.
|
|
71
|
+
A game can be deserialised using `new Game({ serialisedState: gameJson })`.
|
|
72
|
+
|
|
73
|
+
However, when deserialising a game, arguments like `shorthandMode` or `stackPlusTwos` are not
|
|
74
|
+
allowed, since they were already set when the game was being initiated.
|
|
75
|
+
|
|
76
|
+
# Error Reporting
|
|
77
|
+
|
|
78
|
+
If a player tries to perform an invalid move, such as drawing twice in a row or playing a card
|
|
79
|
+
that is not allowed, an `UnocabError` will be thrown. The message provides an adequate description
|
|
80
|
+
of what the problem was, but you can also access information pertaining to the error using the `code` and `data` fields in an `UnocabError`. Please have a look at `errors.ts` for the variations of error codes and the data they provide.
|
|
81
|
+
|
|
82
|
+
# Types
|
|
83
|
+
|
|
84
|
+
Unocab provides Zod types for most of the objects it uses in case you're building something like a REST API and want to verify the structure. Please glance over the `types.ts` file to figure out what Zod types are provided.
|
|
85
|
+
|
|
86
|
+
# GameEvent
|
|
87
|
+
|
|
88
|
+
A game event is an object with a `type` that denotes what kind of event it is (e.g. `draw` or `card_played`), and additional info about that particular event, such as the `card` property in a `card_played` event.
|
|
89
|
+
|
|
90
|
+
It looks like `{ type: "card_played", by: "player-one", card: { type: "six", color: "red" } }`.
|
|
91
|
+
|
|
92
|
+
> NOTE: In full mode (aka not shorthand mode), the events array will also contain events with type `game_info`. These events are not a result of player's actions, but are added by the engine to denote certain happenings. For example, when a player calls bluff, a `game_info` event will be added afterwards to signify whether the bluff call succeeded or failed. This can be helpful for something like implementation of animations when re-playing the game.
|
|
93
|
+
|
|
94
|
+
For more information about what events exist, please glance over the `types.ts` file.
|
|
95
|
+
|
|
96
|
+
# Fetching valid events
|
|
97
|
+
|
|
98
|
+
To obtain a list of "options" for the active player in a game, use `game.validEvents(playerId)`.
|
|
99
|
+
This will return an array of `GameEvent`s which the player is allowed to act on. These events can
|
|
100
|
+
directly be used like `game.processNewEvent(event)`, which acts as an alternative to functions like
|
|
101
|
+
`game.draw` or `game.pass`, which internally use `processNewEvent` as well.
|
|
102
|
+
|
|
103
|
+
# Demo implementations
|
|
104
|
+
|
|
105
|
+
Please refer to `impls/cli-uno.ts` for a cli-based game with an AI.
|
|
106
|
+
There's also `impls/autoplay.ts`, which is an AI vs AI game.
|
|
107
|
+
|
|
108
|
+
(AI here naturally means if conditions, ofcourse!)
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
2
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "crypto"> & {
|
|
3
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
4
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { crypto } from "@deno/shim-crypto";
|
|
2
|
+
export { crypto } from "@deno/shim-crypto";
|
|
3
|
+
const dntGlobals = {
|
|
4
|
+
crypto,
|
|
5
|
+
};
|
|
6
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
7
|
+
// deno-lint-ignore ban-types
|
|
8
|
+
function createMergeProxy(baseObj, extObj) {
|
|
9
|
+
return new Proxy(baseObj, {
|
|
10
|
+
get(_target, prop, _receiver) {
|
|
11
|
+
if (prop in extObj) {
|
|
12
|
+
return extObj[prop];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return baseObj[prop];
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
set(_target, prop, value) {
|
|
19
|
+
if (prop in extObj) {
|
|
20
|
+
delete extObj[prop];
|
|
21
|
+
}
|
|
22
|
+
baseObj[prop] = value;
|
|
23
|
+
return true;
|
|
24
|
+
},
|
|
25
|
+
deleteProperty(_target, prop) {
|
|
26
|
+
let success = false;
|
|
27
|
+
if (prop in extObj) {
|
|
28
|
+
delete extObj[prop];
|
|
29
|
+
success = true;
|
|
30
|
+
}
|
|
31
|
+
if (prop in baseObj) {
|
|
32
|
+
delete baseObj[prop];
|
|
33
|
+
success = true;
|
|
34
|
+
}
|
|
35
|
+
return success;
|
|
36
|
+
},
|
|
37
|
+
ownKeys(_target) {
|
|
38
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
39
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
40
|
+
const extKeysSet = new Set(extKeys);
|
|
41
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
42
|
+
},
|
|
43
|
+
defineProperty(_target, prop, desc) {
|
|
44
|
+
if (prop in extObj) {
|
|
45
|
+
delete extObj[prop];
|
|
46
|
+
}
|
|
47
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
48
|
+
return true;
|
|
49
|
+
},
|
|
50
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
51
|
+
if (prop in extObj) {
|
|
52
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
has(_target, prop) {
|
|
59
|
+
return prop in extObj || prop in baseObj;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno-test";
|
|
2
|
+
export { Deno } from "@deno/shim-deno-test";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "crypto" | "Deno"> & {
|
|
5
|
+
Deno: typeof Deno;
|
|
6
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
7
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/** RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff` */
|
|
2
|
+
interface Rgb {
|
|
3
|
+
r: number;
|
|
4
|
+
g: number;
|
|
5
|
+
b: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Set changing text color to enabled or disabled
|
|
9
|
+
* @param value
|
|
10
|
+
*/
|
|
11
|
+
export declare function setColorEnabled(value: boolean): void;
|
|
12
|
+
/** Get whether text color change is enabled or disabled. */
|
|
13
|
+
export declare function getColorEnabled(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Reset the text modified
|
|
16
|
+
* @param str text to reset
|
|
17
|
+
*/
|
|
18
|
+
export declare function reset(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Make the text bold.
|
|
21
|
+
* @param str text to make bold
|
|
22
|
+
*/
|
|
23
|
+
export declare function bold(str: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* The text emits only a small amount of light.
|
|
26
|
+
* @param str text to dim
|
|
27
|
+
*/
|
|
28
|
+
export declare function dim(str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Make the text italic.
|
|
31
|
+
* @param str text to make italic
|
|
32
|
+
*/
|
|
33
|
+
export declare function italic(str: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Make the text underline.
|
|
36
|
+
* @param str text to underline
|
|
37
|
+
*/
|
|
38
|
+
export declare function underline(str: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Invert background color and text color.
|
|
41
|
+
* @param str text to invert its color
|
|
42
|
+
*/
|
|
43
|
+
export declare function inverse(str: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Make the text hidden.
|
|
46
|
+
* @param str text to hide
|
|
47
|
+
*/
|
|
48
|
+
export declare function hidden(str: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Put horizontal line through the center of the text.
|
|
51
|
+
* @param str text to strike through
|
|
52
|
+
*/
|
|
53
|
+
export declare function strikethrough(str: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Set text color to black.
|
|
56
|
+
* @param str text to make black
|
|
57
|
+
*/
|
|
58
|
+
export declare function black(str: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Set text color to red.
|
|
61
|
+
* @param str text to make red
|
|
62
|
+
*/
|
|
63
|
+
export declare function red(str: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Set text color to green.
|
|
66
|
+
* @param str text to make green
|
|
67
|
+
*/
|
|
68
|
+
export declare function green(str: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Set text color to yellow.
|
|
71
|
+
* @param str text to make yellow
|
|
72
|
+
*/
|
|
73
|
+
export declare function yellow(str: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Set text color to blue.
|
|
76
|
+
* @param str text to make blue
|
|
77
|
+
*/
|
|
78
|
+
export declare function blue(str: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Set text color to magenta.
|
|
81
|
+
* @param str text to make magenta
|
|
82
|
+
*/
|
|
83
|
+
export declare function magenta(str: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Set text color to cyan.
|
|
86
|
+
* @param str text to make cyan
|
|
87
|
+
*/
|
|
88
|
+
export declare function cyan(str: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Set text color to white.
|
|
91
|
+
* @param str text to make white
|
|
92
|
+
*/
|
|
93
|
+
export declare function white(str: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Set text color to gray.
|
|
96
|
+
* @param str text to make gray
|
|
97
|
+
*/
|
|
98
|
+
export declare function gray(str: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Set text color to bright black.
|
|
101
|
+
* @param str text to make bright-black
|
|
102
|
+
*/
|
|
103
|
+
export declare function brightBlack(str: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* Set text color to bright red.
|
|
106
|
+
* @param str text to make bright-red
|
|
107
|
+
*/
|
|
108
|
+
export declare function brightRed(str: string): string;
|
|
109
|
+
/**
|
|
110
|
+
* Set text color to bright green.
|
|
111
|
+
* @param str text to make bright-green
|
|
112
|
+
*/
|
|
113
|
+
export declare function brightGreen(str: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Set text color to bright yellow.
|
|
116
|
+
* @param str text to make bright-yellow
|
|
117
|
+
*/
|
|
118
|
+
export declare function brightYellow(str: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Set text color to bright blue.
|
|
121
|
+
* @param str text to make bright-blue
|
|
122
|
+
*/
|
|
123
|
+
export declare function brightBlue(str: string): string;
|
|
124
|
+
/**
|
|
125
|
+
* Set text color to bright magenta.
|
|
126
|
+
* @param str text to make bright-magenta
|
|
127
|
+
*/
|
|
128
|
+
export declare function brightMagenta(str: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Set text color to bright cyan.
|
|
131
|
+
* @param str text to make bright-cyan
|
|
132
|
+
*/
|
|
133
|
+
export declare function brightCyan(str: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Set text color to bright white.
|
|
136
|
+
* @param str text to make bright-white
|
|
137
|
+
*/
|
|
138
|
+
export declare function brightWhite(str: string): string;
|
|
139
|
+
/**
|
|
140
|
+
* Set background color to black.
|
|
141
|
+
* @param str text to make its background black
|
|
142
|
+
*/
|
|
143
|
+
export declare function bgBlack(str: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Set background color to red.
|
|
146
|
+
* @param str text to make its background red
|
|
147
|
+
*/
|
|
148
|
+
export declare function bgRed(str: string): string;
|
|
149
|
+
/**
|
|
150
|
+
* Set background color to green.
|
|
151
|
+
* @param str text to make its background green
|
|
152
|
+
*/
|
|
153
|
+
export declare function bgGreen(str: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Set background color to yellow.
|
|
156
|
+
* @param str text to make its background yellow
|
|
157
|
+
*/
|
|
158
|
+
export declare function bgYellow(str: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Set background color to blue.
|
|
161
|
+
* @param str text to make its background blue
|
|
162
|
+
*/
|
|
163
|
+
export declare function bgBlue(str: string): string;
|
|
164
|
+
/**
|
|
165
|
+
* Set background color to magenta.
|
|
166
|
+
* @param str text to make its background magenta
|
|
167
|
+
*/
|
|
168
|
+
export declare function bgMagenta(str: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Set background color to cyan.
|
|
171
|
+
* @param str text to make its background cyan
|
|
172
|
+
*/
|
|
173
|
+
export declare function bgCyan(str: string): string;
|
|
174
|
+
/**
|
|
175
|
+
* Set background color to white.
|
|
176
|
+
* @param str text to make its background white
|
|
177
|
+
*/
|
|
178
|
+
export declare function bgWhite(str: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Set background color to bright black.
|
|
181
|
+
* @param str text to make its background bright-black
|
|
182
|
+
*/
|
|
183
|
+
export declare function bgBrightBlack(str: string): string;
|
|
184
|
+
/**
|
|
185
|
+
* Set background color to bright red.
|
|
186
|
+
* @param str text to make its background bright-red
|
|
187
|
+
*/
|
|
188
|
+
export declare function bgBrightRed(str: string): string;
|
|
189
|
+
/**
|
|
190
|
+
* Set background color to bright green.
|
|
191
|
+
* @param str text to make its background bright-green
|
|
192
|
+
*/
|
|
193
|
+
export declare function bgBrightGreen(str: string): string;
|
|
194
|
+
/**
|
|
195
|
+
* Set background color to bright yellow.
|
|
196
|
+
* @param str text to make its background bright-yellow
|
|
197
|
+
*/
|
|
198
|
+
export declare function bgBrightYellow(str: string): string;
|
|
199
|
+
/**
|
|
200
|
+
* Set background color to bright blue.
|
|
201
|
+
* @param str text to make its background bright-blue
|
|
202
|
+
*/
|
|
203
|
+
export declare function bgBrightBlue(str: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* Set background color to bright magenta.
|
|
206
|
+
* @param str text to make its background bright-magenta
|
|
207
|
+
*/
|
|
208
|
+
export declare function bgBrightMagenta(str: string): string;
|
|
209
|
+
/**
|
|
210
|
+
* Set background color to bright cyan.
|
|
211
|
+
* @param str text to make its background bright-cyan
|
|
212
|
+
*/
|
|
213
|
+
export declare function bgBrightCyan(str: string): string;
|
|
214
|
+
/**
|
|
215
|
+
* Set background color to bright white.
|
|
216
|
+
* @param str text to make its background bright-white
|
|
217
|
+
*/
|
|
218
|
+
export declare function bgBrightWhite(str: string): string;
|
|
219
|
+
/**
|
|
220
|
+
* Set text color using paletted 8bit colors.
|
|
221
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
222
|
+
* @param str text color to apply paletted 8bit colors to
|
|
223
|
+
* @param color code
|
|
224
|
+
*/
|
|
225
|
+
export declare function rgb8(str: string, color: number): string;
|
|
226
|
+
/**
|
|
227
|
+
* Set background color using paletted 8bit colors.
|
|
228
|
+
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
|
229
|
+
* @param str text color to apply paletted 8bit background colors to
|
|
230
|
+
* @param color code
|
|
231
|
+
*/
|
|
232
|
+
export declare function bgRgb8(str: string, color: number): string;
|
|
233
|
+
/**
|
|
234
|
+
* Set text color using 24bit rgb.
|
|
235
|
+
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
236
|
+
* an `Rgb`.
|
|
237
|
+
*
|
|
238
|
+
* To produce the color magenta:
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { rgb24 } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
242
|
+
* rgb24("foo", 0xff00ff);
|
|
243
|
+
* rgb24("foo", {r: 255, g: 0, b: 255});
|
|
244
|
+
* ```
|
|
245
|
+
* @param str text color to apply 24bit rgb to
|
|
246
|
+
* @param color code
|
|
247
|
+
*/
|
|
248
|
+
export declare function rgb24(str: string, color: number | Rgb): string;
|
|
249
|
+
/**
|
|
250
|
+
* Set background color using 24bit rgb.
|
|
251
|
+
* `color` can be a number in range `0x000000` to `0xffffff` or
|
|
252
|
+
* an `Rgb`.
|
|
253
|
+
*
|
|
254
|
+
* To produce the color magenta:
|
|
255
|
+
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* import { bgRgb24 } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts";
|
|
258
|
+
* bgRgb24("foo", 0xff00ff);
|
|
259
|
+
* bgRgb24("foo", {r: 255, g: 0, b: 255});
|
|
260
|
+
* ```
|
|
261
|
+
* @param str text color to apply 24bit rgb to
|
|
262
|
+
* @param color code
|
|
263
|
+
*/
|
|
264
|
+
export declare function bgRgb24(str: string, color: number | Rgb): string;
|
|
265
|
+
/**
|
|
266
|
+
* Remove ANSI escape codes from the string.
|
|
267
|
+
* @param string to remove ANSI escape codes from
|
|
268
|
+
*/
|
|
269
|
+
export declare function stripColor(string: string): string;
|
|
270
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum DiffType {
|
|
2
|
+
removed = "removed",
|
|
3
|
+
common = "common",
|
|
4
|
+
added = "added"
|
|
5
|
+
}
|
|
6
|
+
export interface DiffResult<T> {
|
|
7
|
+
type: DiffType;
|
|
8
|
+
value: T;
|
|
9
|
+
details?: Array<DiffResult<T>>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders the differences between the actual and expected values
|
|
13
|
+
* @param A Actual value
|
|
14
|
+
* @param B Expected value
|
|
15
|
+
*/
|
|
16
|
+
export declare function diff<T>(A: T[], B: T[]): Array<DiffResult<T>>;
|
|
17
|
+
/**
|
|
18
|
+
* Renders the differences between the actual and expected strings
|
|
19
|
+
* Partially inspired from https://github.com/kpdecker/jsdiff
|
|
20
|
+
* @param A Actual string
|
|
21
|
+
* @param B Expected string
|
|
22
|
+
*/
|
|
23
|
+
export declare function diffstr(A: string, B: string): DiffResult<string>[];
|
|
24
|
+
export declare function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>, { stringDiff }?: {
|
|
25
|
+
stringDiff?: boolean | undefined;
|
|
26
|
+
}): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function format(v: unknown): string;
|