creo 0.0.2 → 0.0.3-dev

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/README.md CHANGED
@@ -1,52 +1 @@
1
- # @duorun/Maybe
2
-
3
- TypeScript implementation maybe monad.
4
-
5
- 1. Easy-to-use
6
- 2. Small (267 Bytes)!
7
- 3. Typed API
8
-
9
- ## Install:
10
-
11
- ```shell
12
- npm i @duorun/maybe --save
13
- ```
14
-
15
- ## Playground:
16
-
17
- Sandbox: https://codesandbox.io/p/sandbox/nifty-lake-5wpq2y
18
-
19
- ## Usages
20
-
21
- Value is defined:
22
-
23
- ```js
24
- just("bar"); // Maybe<string>
25
- ```
26
-
27
- Value is empty:
28
-
29
- ```js
30
- none(); // Maybe<never>
31
- ```
32
-
33
- Note: null / undefeind can be valid data:
34
-
35
- ```js
36
- just(null); // Maybe<null>
37
- ```
38
-
39
- Check if value is defined:
40
-
41
- ```js
42
- import { isNone } from "@duorun/maybe";
43
-
44
- function test(maybe: Maybe<string>) {
45
- if (isNone(maybe)) {
46
- // maybe is None
47
- } else {
48
- // maybe is just
49
- maybe.value; // string
50
- }
51
- }
52
- ```
1
+ Work in progress, stay tuned
package/bun.lockb ADDED
Binary file
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Vite + TS</title>
8
+ </head>
9
+ <body>
10
+ <div id="app"></div>
11
+ <script type="module" src="/src/main.ts"></script>
12
+ </body>
13
+ </html>
package/package.json CHANGED
@@ -1,52 +1,15 @@
1
1
  {
2
2
  "name": "creo",
3
- "version": "0.0.2",
4
- "description": "Simple and typed Maybe monad",
3
+ "version": "0.0.3-dev",
5
4
  "type": "module",
6
- "source": "./index.ts",
7
- "main": "dist/index.js",
8
- "module": "dist/index.js",
9
- "esmodule": "dist/index.mjs",
10
- "umd:main": "dist/index.umd.js",
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "module": "./dist/index.module.js",
15
- "import": "./dist/index.mjs",
16
- "require": "./dist/index.js"
17
- },
18
- "./package.json": "./package.json"
19
- },
20
- "sideEffects": false,
21
- "devDependencies": {
22
- "@size-limit/preset-small-lib": "^11.0.0",
23
- "bun-types": "latest",
24
- "size-limit": "^11.0.0"
25
- },
26
- "peerDependencies": {
27
- "typescript": "^5.0.0"
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "git+ssh://git@github.com/xnimorz/maybe.git"
32
- },
33
- "browserslist": ["last 2 years", "node >= 12"],
34
- "author": "Nik (nik@xnim.me)",
35
- "license": "MIT",
36
- "files": ["dist"],
37
- "bugs": {
38
- "url": "https://github.com/xnimorz/maybe/issues"
39
- },
40
- "homepage": "https://github.com/xnimorz/maybe#readme",
41
- "keywords": ["monad", "maybe", "ts-maybe"],
42
5
  "scripts": {
43
- "build": "microbundle build --entry ./index.ts --name @duorun/maybe --tsconfig tsconfig.json --compress false & bun run size-limit",
44
- "prepublishOnly": "bun test & bun run build"
6
+ "dev": "vite",
7
+ "build": "tsc && vite build",
8
+ "preview": "vite preview"
45
9
  },
46
- "size-limit": [
47
- {
48
- "path": "dist/index.js",
49
- "limit": "270 B"
50
- }
51
- ]
10
+ "devDependencies": {
11
+ "typescript": "^5.2.2",
12
+ "vite": "^5.2.0",
13
+ "bun-types": "latest"
14
+ }
52
15
  }
package/src/main.ts ADDED
@@ -0,0 +1,13 @@
1
+ import "./style.css";
2
+
3
+ document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
4
+ <div>
5
+ <h1>Vite + TypeScript</h1>
6
+ <div class="card">
7
+ <button id="counter" type="button"></button>
8
+ </div>
9
+ <p class="read-the-docs">
10
+ Click on the Vite and TypeScript logos to learn more
11
+ </p>
12
+ </div>
13
+ `;
@@ -0,0 +1,146 @@
1
+ import { expect, test } from "bun:test";
2
+ import { record, onDidUpdate } from "./record";
3
+
4
+ test("Can define objects", () => {
5
+ const obj = record({
6
+ hello: "world",
7
+ });
8
+
9
+ expect(obj).toEqual({ hello: "world" });
10
+ });
11
+
12
+ test("Notifies on object updates", async () => {
13
+ const obj = record({
14
+ hello: "world",
15
+ });
16
+
17
+ await expect(
18
+ new Promise((resolve) => {
19
+ onDidUpdate(obj, (updated) => resolve(updated));
20
+
21
+ obj.hello = "new world";
22
+ }),
23
+ ).resolves.toEqual({
24
+ hello: "new world",
25
+ });
26
+ });
27
+
28
+ test("Notifies on object updates even if the listener was set after the change", async () => {
29
+ const obj = record({
30
+ hello: "world",
31
+ });
32
+
33
+ obj.hello = "new world";
34
+
35
+ await expect(
36
+ new Promise((resolve) => {
37
+ onDidUpdate(obj, (updated) => resolve(updated));
38
+ }),
39
+ ).resolves.toEqual({
40
+ hello: "new world",
41
+ });
42
+ });
43
+
44
+ test("Implies updates immediately", async () => {
45
+ const obj = record({
46
+ hello: {
47
+ world: "foo",
48
+ },
49
+ });
50
+
51
+ expect(obj).toEqual({
52
+ hello: {
53
+ world: "foo",
54
+ },
55
+ });
56
+
57
+ obj.hello.world = "new";
58
+
59
+ expect(obj).toEqual({
60
+ hello: {
61
+ world: "new",
62
+ },
63
+ });
64
+ });
65
+
66
+ test("Handles nested object updates", async () => {
67
+ const obj = record({
68
+ hello: {
69
+ world: "foo",
70
+ },
71
+ });
72
+
73
+ obj.hello.world = "new";
74
+
75
+ await expect(
76
+ new Promise((resolve) => {
77
+ onDidUpdate(obj, (updated) => resolve(updated));
78
+ }),
79
+ ).resolves.toEqual({
80
+ hello: {
81
+ world: "new",
82
+ },
83
+ });
84
+ });
85
+
86
+ test("Can unsubscribe from updates", async () => {
87
+ const obj = record({
88
+ hello: {
89
+ world: "foo",
90
+ },
91
+ });
92
+
93
+ const unsubscribe = onDidUpdate(obj, (_updated) => {
94
+ throw Error("cannot get here");
95
+ });
96
+ // If you delete this line, the test gets broken:
97
+ unsubscribe();
98
+
99
+ obj.hello.world = "new";
100
+
101
+ await expect(
102
+ new Promise((resolve) => {
103
+ onDidUpdate(obj, (updated) => resolve(updated));
104
+ }),
105
+ ).resolves.toEqual({
106
+ hello: {
107
+ world: "new",
108
+ },
109
+ });
110
+ });
111
+
112
+ test("Supports arrays", async () => {
113
+ const obj = record({
114
+ hello: {
115
+ world: ["this", "is", "array"],
116
+ },
117
+ });
118
+
119
+ obj.hello.world.sort();
120
+
121
+ await expect(
122
+ new Promise((resolve) => {
123
+ onDidUpdate(obj, (updated) => resolve(JSON.stringify(updated)));
124
+ }),
125
+ ).resolves.toEqual('{"hello":{"world":["array","is","this"]}}');
126
+
127
+ obj.hello.world.push("123");
128
+
129
+ await expect(
130
+ new Promise((resolve) => {
131
+ onDidUpdate(obj, (updated) => resolve(JSON.stringify(updated)));
132
+ }),
133
+ ).resolves.toEqual('{"hello":{"world":["array","is","this","123"]}}');
134
+ });
135
+
136
+ test("Supports iterable", async () => {
137
+ const obj = record(["hello", "world"]);
138
+
139
+ function iterate(...args: string[]) {
140
+ const [a, b] = args;
141
+ expect(a).toBe("hello");
142
+ expect(b).toBe("world");
143
+ }
144
+
145
+ iterate(...obj);
146
+ });
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Ideas:
3
+ * [x] didUpdate support
4
+ * [x] Proxy proxifies all children as well
5
+ * [ ] Keep track on updates, until there are no users on the old state
6
+ * [ ] Support symbol iterator
7
+ * [ ] Add js dispose tracker to automatically close listeners
8
+ */
9
+
10
+ import { isRecordLike } from "../tools/isRecordLike";
11
+
12
+ type Record<T extends object> = T;
13
+ type Wildcard = any;
14
+ type RecordDidChangeListener<T extends object> = (record: Record<T>) => void;
15
+
16
+ const didUpdateMap: WeakMap<
17
+ Record<Wildcard>,
18
+ Set<RecordDidChangeListener<Wildcard>>
19
+ > = new WeakMap();
20
+
21
+ const scheduledUpdatesNotifiers: Set<Record<Wildcard>> = new Set();
22
+ let shouldScheduleMicrotask = true;
23
+ function queuedNotifier() {
24
+ shouldScheduleMicrotask = true;
25
+ scheduledUpdatesNotifiers.forEach((record) => {
26
+ const listeners = didUpdateMap.get(record);
27
+ if (!listeners) {
28
+ return;
29
+ }
30
+ listeners.forEach((listener) => {
31
+ listener(record);
32
+ });
33
+ });
34
+ }
35
+ function recordDidUpdate<T extends object>(record: Record<T>) {
36
+ scheduledUpdatesNotifiers.add(record);
37
+ shouldScheduleMicrotask && queueMicrotask(queuedNotifier);
38
+ shouldScheduleMicrotask = false;
39
+ }
40
+
41
+ function creoRecord<TNode extends object, T extends object>(
42
+ rootRecord: Record<TNode>,
43
+ value: T,
44
+ ): Record<T> {
45
+ return new Proxy(value, {
46
+ // @ts-ignore we override `get` to improve typing
47
+ get<K extends keyof T>(target: T, property: K): T[K] {
48
+ const val = target[property];
49
+ if (isRecordLike(val)) {
50
+ // @ts-ignore we proxify all nested objects / arrays to ensure correct behaviour
51
+ return creoRecord(rootRecord, val);
52
+ }
53
+ return val;
54
+ },
55
+ // @ts-ignore
56
+ set<K, TNewValue>(target: T, property: K, newValue: TNewValue) {
57
+ // @ts-ignore
58
+ target[property] = newValue;
59
+ recordDidUpdate(rootRecord);
60
+ return true;
61
+ },
62
+ });
63
+ }
64
+
65
+ export function record<TNode extends object>(value: TNode): Record<TNode> {
66
+ const rootRecord = new Proxy(value, {
67
+ // @ts-ignore we override `get` to improve typing
68
+ get<K extends keyof T>(target: T, property: K): T[K] {
69
+ const val = target[property];
70
+ if (isRecordLike(val)) {
71
+ // @ts-ignore we proxify all nested objects / arrays to ensure correct behaviour
72
+ return creoRecord(rootRecord, val);
73
+ }
74
+ return val;
75
+ },
76
+ // @ts-ignore
77
+ set<K, TNewValue>(target: T, property: K, newValue: TNewValue) {
78
+ // @ts-ignore
79
+ target[property] = newValue;
80
+ recordDidUpdate(rootRecord);
81
+ return true;
82
+ },
83
+ });
84
+ didUpdateMap.set(rootRecord, new Set());
85
+ return rootRecord;
86
+ }
87
+
88
+ export function onDidUpdate<T extends object>(
89
+ record: Record<T>,
90
+ listener: (record: Record<T>) => void,
91
+ ): () => void {
92
+ const listeners = didUpdateMap.get(record);
93
+ if (!listeners) {
94
+ // Safe-guard: Essentialy this path cannot happen
95
+ throw new TypeError(`Record ${record} was created without listener`);
96
+ }
97
+ listeners.add(listener);
98
+ return function unsubscribe() {
99
+ listeners.delete(listener);
100
+ };
101
+ }
package/src/style.css ADDED
@@ -0,0 +1,96 @@
1
+ :root {
2
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 1.5;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ }
15
+
16
+ a {
17
+ font-weight: 500;
18
+ color: #646cff;
19
+ text-decoration: inherit;
20
+ }
21
+ a:hover {
22
+ color: #535bf2;
23
+ }
24
+
25
+ body {
26
+ margin: 0;
27
+ display: flex;
28
+ place-items: center;
29
+ min-width: 320px;
30
+ min-height: 100vh;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 3.2em;
35
+ line-height: 1.1;
36
+ }
37
+
38
+ #app {
39
+ max-width: 1280px;
40
+ margin: 0 auto;
41
+ padding: 2rem;
42
+ text-align: center;
43
+ }
44
+
45
+ .logo {
46
+ height: 6em;
47
+ padding: 1.5em;
48
+ will-change: filter;
49
+ transition: filter 300ms;
50
+ }
51
+ .logo:hover {
52
+ filter: drop-shadow(0 0 2em #646cffaa);
53
+ }
54
+ .logo.vanilla:hover {
55
+ filter: drop-shadow(0 0 2em #3178c6aa);
56
+ }
57
+
58
+ .card {
59
+ padding: 2em;
60
+ }
61
+
62
+ .read-the-docs {
63
+ color: #888;
64
+ }
65
+
66
+ button {
67
+ border-radius: 8px;
68
+ border: 1px solid transparent;
69
+ padding: 0.6em 1.2em;
70
+ font-size: 1em;
71
+ font-weight: 500;
72
+ font-family: inherit;
73
+ background-color: #1a1a1a;
74
+ cursor: pointer;
75
+ transition: border-color 0.25s;
76
+ }
77
+ button:hover {
78
+ border-color: #646cff;
79
+ }
80
+ button:focus,
81
+ button:focus-visible {
82
+ outline: 4px auto -webkit-focus-ring-color;
83
+ }
84
+
85
+ @media (prefers-color-scheme: light) {
86
+ :root {
87
+ color: #213547;
88
+ background-color: #ffffff;
89
+ }
90
+ a:hover {
91
+ color: #747bff;
92
+ }
93
+ button {
94
+ background-color: #f9f9f9;
95
+ }
96
+ }
@@ -0,0 +1,29 @@
1
+ import { expect, test } from "bun:test";
2
+ import { isRecordLike } from "./isRecordLike";
3
+
4
+ test("Handles objects", () => {
5
+ expect(isRecordLike({})).toBe(true);
6
+ expect(isRecordLike({ foo: "bar" })).toBe(true);
7
+ expect(isRecordLike(new String())).toBe(true);
8
+ });
9
+
10
+ test("Handles arrays", () => {
11
+ expect(isRecordLike([])).toBe(true);
12
+ });
13
+
14
+ test("Fails nulls", () => {
15
+ expect(isRecordLike(null)).toBe(false);
16
+ expect(isRecordLike(undefined)).toBe(false);
17
+ expect(isRecordLike(NaN)).toBe(false);
18
+ expect(isRecordLike(0)).toBe(false);
19
+ expect(isRecordLike(false)).toBe(false);
20
+ expect(isRecordLike("")).toBe(false);
21
+ });
22
+
23
+ test("Fails primitives", () => {
24
+ expect(isRecordLike(1)).toBe(false);
25
+ expect(isRecordLike("foo")).toBe(false);
26
+ // @ts-ignore
27
+ expect(isRecordLike()).toBe(false);
28
+ expect(isRecordLike(Symbol.for("test"))).toBe(false);
29
+ });
@@ -0,0 +1,3 @@
1
+ export function isRecordLike<T, K extends object>(value: T | K): value is K {
2
+ return (typeof value === "object" || Array.isArray(value)) && value != null;
3
+ }
@@ -0,0 +1,25 @@
1
+ export type None = null;
2
+ export type Just<T> = T;
3
+ export type Optional<T> = Just<T> | None;
4
+
5
+ export function isJust<T>(v: Optional<T>): v is Just<T> {
6
+ return v != null;
7
+ }
8
+
9
+ export function isNone<T>(v: Optional<T>): v is None {
10
+ return v == null;
11
+ }
12
+
13
+ export function unwrap<T>(v: Optional<T>): Just<T> {
14
+ if (isJust(v)) {
15
+ return v;
16
+ }
17
+ throw new TypeError("Optional is none");
18
+ }
19
+
20
+ export function orDefault<T, K>(v: Optional<T>, alternative: K) {
21
+ if (isJust(v)) {
22
+ return v;
23
+ }
24
+ return alternative;
25
+ }
@@ -0,0 +1 @@
1
+ function
File without changes
package/src/ui/prop.ts ADDED
@@ -0,0 +1,13 @@
1
+ export const $prop = {
2
+ ofString: () => {
3
+ return {
4
+
5
+ }
6
+ },
7
+ ofNumber: (prop: number) => {
8
+
9
+ },
10
+ of<T>: (prop: T) => {
11
+
12
+ }
13
+ }
File without changes
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noFallthroughCasesInSwitch": true
21
+ },
22
+ "include": ["src"]
23
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Nik Mostovoy
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/dist/index.cjs DELETED
@@ -1,54 +0,0 @@
1
- var id = 0;
2
- function _classPrivateFieldLooseKey(name) {
3
- return "__private_" + id++ + "_" + name;
4
- }
5
- function _classPrivateFieldLooseBase(receiver, privateKey) {
6
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
7
- throw new TypeError("attempted to use private field on non-instance");
8
- }
9
- return receiver;
10
- }
11
-
12
- const JUST = true;
13
- const NONE = false;
14
- var _type = /*#__PURE__*/_classPrivateFieldLooseKey("type");
15
- var _value = /*#__PURE__*/_classPrivateFieldLooseKey("value");
16
- class CMaybe {
17
- constructor(type, value) {
18
- Object.defineProperty(this, _type, {
19
- writable: true,
20
- value: void 0
21
- });
22
- Object.defineProperty(this, _value, {
23
- writable: true,
24
- value: void 0
25
- });
26
- _classPrivateFieldLooseBase(this, _type)[_type] = type;
27
- _classPrivateFieldLooseBase(this, _value)[_value] = value;
28
- }
29
- get value() {
30
- return _classPrivateFieldLooseBase(this, _value)[_value];
31
- }
32
- isNone() {
33
- return _classPrivateFieldLooseBase(this, _type)[_type] === NONE;
34
- }
35
- }
36
- function just(value) {
37
- return new CMaybe(JUST, value);
38
- }
39
- function none() {
40
- // @ts-expect-error We ignore here as maybe.value will never be accessible at this point
41
- return new CMaybe(NONE, undefined);
42
- }
43
- function isNone(maybe) {
44
- return maybe.isNone();
45
- }
46
- function isJust(maybe) {
47
- return !maybe.isNone();
48
- }
49
-
50
- exports.isJust = isJust;
51
- exports.isNone = isNone;
52
- exports.just = just;
53
- exports.none = none;
54
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../index.ts"],"sourcesContent":["const JUST = true as const;\ntype TJust = typeof JUST;\nconst NONE = false as const;\ntype TNone = typeof NONE;\ntype STATE = TJust | TNone;\n\nclass CMaybe<TValue, TState extends STATE = STATE> {\n #type: TState;\n #value: TState extends TJust ? TValue : undefined;\n constructor(type: TState, value: TState extends TJust ? TValue : undefined) {\n this.#type = type;\n this.#value = value;\n }\n\n public get value(): TState extends TJust ? TValue : undefined {\n return this.#value;\n }\n\n isNone(): this is None {\n return this.#type === NONE;\n }\n}\n\nexport type Just<T> = CMaybe<T, TJust>;\nexport type None<T = never> = CMaybe<T, TNone>;\n\nexport type Maybe<T> = Just<T> | None;\n\nexport function just<T>(value: T): Just<T> {\n return new CMaybe(JUST, value);\n}\n\nexport function none<T = never>(): None<T> {\n // @ts-expect-error We ignore here as maybe.value will never be accessible at this point\n return new CMaybe(NONE, undefined);\n}\n\nexport function isNone<T>(maybe: CMaybe<T>): maybe is None {\n return maybe.isNone();\n}\n\nexport function isJust<T>(maybe: CMaybe<T>): maybe is Just<T> {\n return !maybe.isNone();\n}\n"],"names":["JUST","NONE","_type","_classPrivateFieldLooseKey","_value","CMaybe","constructor","type","value","Object","defineProperty","writable","_classPrivateFieldLooseBase","isNone","just","none","undefined","maybe","isJust"],"mappings":";;;;;;;;;;;AAAA,MAAMA,IAAI,GAAG,IAAa,CAAA;AAE1B,MAAMC,IAAI,GAAG,KAAc,CAAA;AAAC,IAAAC,KAAA,gBAAAC,0BAAA,CAAA,MAAA,CAAA,CAAA;AAAA,IAAAC,MAAA,gBAAAD,0BAAA,CAAA,OAAA,CAAA,CAAA;AAI5B,MAAME,MAAM,CAAA;A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19 +0,0 @@
1
- declare const JUST: true;
2
- type TJust = typeof JUST;
3
- declare const NONE: false;
4
- type TNone = typeof NONE;
5
- type STATE = TJust | TNone;
6
- declare class CMaybe<TValue, TState extends STATE = STATE> {
7
- #private;
8
- constructor(type: TState, value: TState extends TJust ? TValue : undefined);
9
- get value(): TState extends TJust ? TValue : undefined;
10
- isNone(): this is None;
11
- }
12
- export type Just<T> = CMaybe<T, TJust>;
13
- export type None<T = never> = CMaybe<T, TNone>;
14
- export type Maybe<T> = Just<T> | None;
15
- export declare function just<T>(value: T): Just<T>;
16
- export declare function none<T = never>(): None<T>;
17
- export declare function isNone<T>(maybe: CMaybe<T>): maybe is None;
18
- export declare function isJust<T>(maybe: CMaybe<T>): maybe is Just<T>;
19
- export {};
package/dist/index.js DELETED
@@ -1,51 +0,0 @@
1
- var id = 0;
2
- function _classPrivateFieldLooseKey(name) {
3
- return "__private_" + id++ + "_" + name;
4
- }
5
- function _classPrivateFieldLooseBase(receiver, privateKey) {
6
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
7
- throw new TypeError("attempted to use private field on non-instance");
8
- }
9
- return receiver;
10
- }
11
-
12
- const JUST = true;
13
- const NONE = false;
14
- var _type = /*#__PURE__*/_classPrivateFieldLooseKey("type");
15
- var _value = /*#__PURE__*/_classPrivateFieldLooseKey("value");
16
- class CMaybe {
17
- constructor(type, value) {
18
- Object.defineProperty(this, _type, {
19
- writable: true,
20
- value: void 0
21
- });
22
- Object.defineProperty(this, _value, {
23
- writable: true,
24
- value: void 0
25
- });
26
- _classPrivateFieldLooseBase(this, _type)[_type] = type;
27
- _classPrivateFieldLooseBase(this, _value)[_value] = value;
28
- }
29
- get value() {
30
- return _classPrivateFieldLooseBase(this, _value)[_value];
31
- }
32
- isNone() {
33
- return _classPrivateFieldLooseBase(this, _type)[_type] === NONE;
34
- }
35
- }
36
- function just(value) {
37
- return new CMaybe(JUST, value);
38
- }
39
- function none() {
40
- // @ts-expect-error We ignore here as maybe.value will never be accessible at this point
41
- return new CMaybe(NONE, undefined);
42
- }
43
- function isNone(maybe) {
44
- return maybe.isNone();
45
- }
46
- function isJust(maybe) {
47
- return !maybe.isNone();
48
- }
49
-
50
- export { isJust, isNone, just, none };
51
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../index.ts"],"sourcesContent":["const JUST = true as const;\ntype TJust = typeof JUST;\nconst NONE = false as const;\ntype TNone = typeof NONE;\ntype STATE = TJust | TNone;\n\nclass CMaybe<TValue, TState extends STATE = STATE> {\n #type: TState;\n #value: TState extends TJust ? TValue : undefined;\n constructor(type: TState, value: TState extends TJust ? TValue : undefined) {\n this.#type = type;\n this.#value = value;\n }\n\n public get value(): TState extends TJust ? TValue : undefined {\n return this.#value;\n }\n\n isNone(): this is None {\n return this.#type === NONE;\n }\n}\n\nexport type Just<T> = CMaybe<T, TJust>;\nexport type None<T = never> = CMaybe<T, TNone>;\n\nexport type Maybe<T> = Just<T> | None;\n\nexport function just<T>(value: T): Just<T> {\n return new CMaybe(JUST, value);\n}\n\nexport function none<T = never>(): None<T> {\n // @ts-expect-error We ignore here as maybe.value will never be accessible at this point\n return new CMaybe(NONE, undefined);\n}\n\nexport function isNone<T>(maybe: CMaybe<T>): maybe is None {\n return maybe.isNone();\n}\n\nexport function isJust<T>(maybe: CMaybe<T>): maybe is Just<T> {\n return !maybe.isNone();\n}\n"],"names":["JUST","NONE","_type","_classPrivateFieldLooseKey","_value","CMaybe","constructor","type","value","Object","defineProperty","writable","_classPrivateFieldLooseBase","isNone","just","none","undefined","maybe","isJust"],"mappings":";;;;;;;;;;;AAAA,MAAMA,IAAI,GAAG,IAAa,CAAA;AAE1B,MAAMC,IAAI,GAAG,KAAc,CAAA;AAAC,IAAAC,KAAA,gBAAAC,0BAAA,CAAA,MAAA,CAAA,CAAA;AAAA,IAAAC,MAAA,gBAAAD,0BAAA,CAAA,OAAA,CAAA,CAAA;AAI5B,MAAME,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
@@ -1,51 +0,0 @@
1
- var id = 0;
2
- function _classPrivateFieldLooseKey(name) {
3
- return "__private_" + id++ + "_" + name;
4
- }
5
- function _classPrivateFieldLooseBase(receiver, privateKey) {
6
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
7
- throw new TypeError("attempted to use private field on non-instance");
8
- }
9
- return receiver;
10
- }
11
-
12
- const JUST = true;
13
- const NONE = false;
14
- var _type = /*#__PURE__*/_classPrivateFieldLooseKey("type");
15
- var _value = /*#__PURE__*/_classPrivateFieldLooseKey("value");
16
- class CMaybe {
17
- constructor(type, value) {
18
- Object.defineProperty(this, _type, {
19
- writable: true,
20
- value: void 0
21
- });
22
- Object.defineProperty(this, _value, {
23
- writable: true,
24
- value: void 0
25
- });
26
- _classPrivateFieldLooseBase(this, _type)[_type] = type;
27
- _classPrivateFieldLooseBase(this, _value)[_value] = value;
28
- }
29
- get value() {
30
- return _classPrivateFieldLooseBase(this, _value)[_value];
31
- }
32
- isNone() {
33
- return _classPrivateFieldLooseBase(this, _type)[_type] === NONE;
34
- }
35
- }
36
- function just(value) {
37
- return new CMaybe(JUST, value);
38
- }
39
- function none() {
40
- // @ts-expect-error We ignore here as maybe.value will never be accessible at this point
41
- return new CMaybe(NONE, undefined);
42
- }
43
- function isNone(maybe) {
44
- return maybe.isNone();
45
- }
46
- function isJust(maybe) {
47
- return !maybe.isNone();
48
- }
49
-
50
- export { isJust, isNone, just, none };
51
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../index.ts"],"sourcesContent":["const JUST = true as const;\ntype TJust = typeof JUST;\nconst NONE = false as const;\ntype TNone = typeof NONE;\ntype STATE = TJust | TNone;\n\nclass CMaybe<TValue, TState extends STATE = STATE> {\n #type: TState;\n #value: TState extends TJust ? TValue : undefined;\n constructor(type: TState, value: TState extends TJust ? TValue : undefined) {\n this.#type = type;\n this.#value = value;\n }\n\n public get value(): TState extends TJust ? TValue : undefined {\n return this.#value;\n }\n\n isNone(): this is None {\n return this.#type === NONE;\n }\n}\n\nexport type Just<T> = CMaybe<T, TJust>;\nexport type None<T = never> = CMaybe<T, TNone>;\n\nexport type Maybe<T> = Just<T> | None;\n\nexport function just<T>(value: T): Just<T> {\n return new CMaybe(JUST, value);\n}\n\nexport function none<T = never>(): None<T> {\n // @ts-expect-error We ignore here as maybe.value will never be accessible at this point\n return new CMaybe(NONE, undefined);\n}\n\nexport function isNone<T>(maybe: CMaybe<T>): maybe is None {\n return maybe.isNone();\n}\n\nexport function isJust<T>(maybe: CMaybe<T>): maybe is Just<T> {\n return !maybe.isNone();\n}\n"],"names":["JUST","NONE","_type","_classPrivateFieldLooseKey","_value","CMaybe","constructor","type","value","Object","defineProperty","writable","_classPrivateFieldLooseBase","isNone","just","none","undefined","maybe","isJust"],"mappings":";;;;;;;;;;;AAAA,MAAMA,IAAI,GAAG,IAAa,CAAA;AAE1B,MAAMC,IAAI,GAAG,KAAc,CAAA;AAAC,IAAAC,KAAA,gBAAAC,0BAAA,CAAA,MAAA,CAAA,CAAA;AAAA,IAAAC,MAAA,gBAAAD,0BAAA,CAAA,OAAA,CAAA,CAAA;AAI5B,MAAME,MAAM,CAAA;AAGVC,EAAAA,WAAYA,CAAAC,IAAY,EAAEC,KAAgD,EAAA;IAAAC,MAAA,CAAAC,cAAA,CAAA,IAAA,EAAAR,KAAA,EAAA;MAAAS,QAAA,EAAA,IAAA;MAAAH,KAAA,EAAA,KAAA,CAAA;AAAA,KAAA,CAAA,CAAA;IAAAC,MAAA,CAAAC,cAAA,CAAA,IAAA,EAAAN,MAAA,EAAA;MAAAO,QAAA,EAAA,IAAA;MAAAH,KAAA,EAAA,KAAA,CAAA;AAAA,KAAA,CAAA,CAAA;AACxEI,IAAAA,2BAAA,KAAI,EAAAV,KAAA,CAAAA,CAAAA,KAAA,IAASK,IAAI,CAAA;AACjBK,IAAAA,2BAAA,KAAI,EAAAR,MAAA,CAAAA,CAAAA,MAAA,IAAUI,KAAK,CAAA;AACrB,GAAA;EAEA,IAAWA,KAAKA,GAAA;AACd,IAAA,OAAAI,2BAAA,CAAO,IAAI,EAAAR,MAAA,EAAAA,MAAA,CAAA,CAAA;AACb,GAAA;AAEAS,EAAAA,MAAMA,GAAA;AACJ,IAAA,OAAOD,2BAAA,CAAI,IAAA,EAAAV,KAAA,CAAAA,CAAAA,KAAA,MAAWD,IAAI,CAAA;AAC5B,GAAA;AACD,CAAA;AAOK,SAAUa,IAAIA,CAAIN,KAAQ,EAAA;AAC9B,EAAA,OAAO,IAAIH,MAAM,CAACL,IAAI,EAAEQ,KAAK,CAAC,CAAA;AAChC,CAAA;SAEgBO,IAAIA,GAAA;AAClB;AACA,EAAA,OAAO,IAAIV,MAAM,CAACJ,IAAI,EAAEe,SAAS,CAAC,CAAA;AACpC,CAAA;AAEM,SAAUH,MAAMA,CAAII,KAAgB,EAAA;AACxC,EAAA,OAAOA,KAAK,CAACJ,MAAM,EAAE,CAAA;AACvB,CAAA;AAEM,SAAUK,MAAMA,CAAID,KAAgB,EAAA;AACxC,EAAA,OAAO,CAACA,KAAK,CAACJ,MAAM,EAAE,CAAA;AACxB;;;;"}
package/dist/index.umd.js DELETED
@@ -1,61 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = global || self, factory(global["@duorun/maybe"] = {}));
5
- })(this, (function (exports) {
6
- var id = 0;
7
- function _classPrivateFieldLooseKey(name) {
8
- return "__private_" + id++ + "_" + name;
9
- }
10
- function _classPrivateFieldLooseBase(receiver, privateKey) {
11
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
12
- throw new TypeError("attempted to use private field on non-instance");
13
- }
14
- return receiver;
15
- }
16
-
17
- const JUST = true;
18
- const NONE = false;
19
- var _type = /*#__PURE__*/_classPrivateFieldLooseKey("type");
20
- var _value = /*#__PURE__*/_classPrivateFieldLooseKey("value");
21
- class CMaybe {
22
- constructor(type, value) {
23
- Object.defineProperty(this, _type, {
24
- writable: true,
25
- value: void 0
26
- });
27
- Object.defineProperty(this, _value, {
28
- writable: true,
29
- value: void 0
30
- });
31
- _classPrivateFieldLooseBase(this, _type)[_type] = type;
32
- _classPrivateFieldLooseBase(this, _value)[_value] = value;
33
- }
34
- get value() {
35
- return _classPrivateFieldLooseBase(this, _value)[_value];
36
- }
37
- isNone() {
38
- return _classPrivateFieldLooseBase(this, _type)[_type] === NONE;
39
- }
40
- }
41
- function just(value) {
42
- return new CMaybe(JUST, value);
43
- }
44
- function none() {
45
- // @ts-expect-error We ignore here as maybe.value will never be accessible at this point
46
- return new CMaybe(NONE, undefined);
47
- }
48
- function isNone(maybe) {
49
- return maybe.isNone();
50
- }
51
- function isJust(maybe) {
52
- return !maybe.isNone();
53
- }
54
-
55
- exports.isJust = isJust;
56
- exports.isNone = isNone;
57
- exports.just = just;
58
- exports.none = none;
59
-
60
- }));
61
- //# sourceMappingURL=index.umd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.umd.js","sources":["../index.ts"],"sourcesContent":["const JUST = true as const;\ntype TJust = typeof JUST;\nconst NONE = false as const;\ntype TNone = typeof NONE;\ntype STATE = TJust | TNone;\n\nclass CMaybe<TValue, TState extends STATE = STATE> {\n #type: TState;\n #value: TState extends TJust ? TValue : undefined;\n constructor(type: TState, value: TState extends TJust ? TValue : undefined) {\n this.#type = type;\n this.#value = value;\n }\n\n public get value(): TState extends TJust ? TValue : undefined {\n return this.#value;\n }\n\n isNone(): this is None {\n return this.#type === NONE;\n }\n}\n\nexport type Just<T> = CMaybe<T, TJust>;\nexport type None<T = never> = CMaybe<T, TNone>;\n\nexport type Maybe<T> = Just<T> | None;\n\nexport function just<T>(value: T): Just<T> {\n return new CMaybe(JUST, value);\n}\n\nexport function none<T = never>(): None<T> {\n // @ts-expect-error We ignore here as maybe.value will never be accessible at this point\n return new CMaybe(NONE, undefined);\n}\n\nexport function isNone<T>(maybe: CMaybe<T>): maybe is None {\n return maybe.isNone();\n}\n\nexport function isJust<T>(maybe: CMaybe<T>): maybe is Just<T> {\n return !maybe.isNone();\n}\n"],"names":["JUST","NONE","_type","_classPrivateFieldLooseKey","_value","CMaybe","constructor","type","value","Object","defineProperty","writable","_classPrivateFieldLooseBase","isNone","just","none","undefined","maybe","isJust"],"mappings":";;;;;;;;;;;;;;;;EAAA,MAAMA,IAAI,GAAG,IAAa,CAAA;EAE1B,MAAMC,IAAI,GAAG,KAAc,CAAA;EAAC,IAAAC,KAAA,gBAAAC,0BAAA,CAAA,MAAA,CAAA,CAAA;EAAA,IAAAC,MAAA,gBAAAD,0BAAA,CAAA,OAAA,CAAA,CAAA;EAI5B,MAAME,MAAM,CAAA;EAGVC,EAAAA,WAAYA,CAAAC,IAAY,EAAEC,KAAgD,EAAA;MAAAC,MAAA,CAAAC,cAAA,CAAA,IAAA,EAAAR,KAAA,EAAA;QAAAS,QAAA,EAAA,IAAA;QAAAH,KAAA,EAAA,KAAA,CAAA;EAAA,KAAA,CAAA,CAAA;MAAAC,MAAA,CAAAC,cAAA,CAAA,IAAA,EAAAN,MAAA,EAAA;QAAAO,QAAA,EAAA,IAAA;QAAAH,KAAA,EAAA,KAAA,CAAA;EAAA,KAAA,CAAA,CAAA;EACxEI,IAAAA,2BAAA,KAAI,EAAAV,KAAA,CAAAA,CAAAA,KAAA,IAASK,IAAI,CAAA;EACjBK,IAAAA,2BAAA,KAAI,EAAAR,MAAA,CAAAA,CAAAA,MAAA,IAAUI,KAAK,CAAA;EACrB,GAAA;IAEA,IAAWA,KAAKA,GAAA;EACd,IAAA,OAAAI,2BAAA,CAAO,IAAI,EAAAR,MAAA,EAAAA,MAAA,CAAA,CAAA;EACb,GAAA;EAEAS,EAAAA,MAAMA,GAAA;EACJ,IAAA,OAAOD,2BAAA,CAAI,IAAA,EAAAV,KAAA,CAAAA,CAAAA,KAAA,MAAWD,IAAI,CAAA;EAC5B,GAAA;EACD,CAAA;EAOK,SAAUa,IA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