tw5-typed 0.0.3 → 0.0.7

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
@@ -15,7 +15,7 @@ Add `tw5-typed` to your `tsconfig.json`'s `compilerOptions`
15
15
  ```json
16
16
  {
17
17
  "compilerOptions": {
18
- "types": ["node", "tw5-typed"] /* Type declaration files to be included in compilation. */,
18
+ "types": ["node", "tw5-typed"] /* Type declaration files to be included in compilation. */
19
19
  }
20
20
  }
21
21
  ```
@@ -23,5 +23,33 @@ Add `tw5-typed` to your `tsconfig.json`'s `compilerOptions`
23
23
  Then you will have global types like `$tw` automatically. You can import the rest of the types using `import type` statement:
24
24
 
25
25
  ```typescript
26
+ import type { ISearchOptions, SourceIterator, IFilterOperatorParamOperator } from 'tiddlywiki';
27
+ ```
28
+
29
+ ### Alias
30
+
31
+ Sometimes you may want to use a modified version of tw, you can re-export types like this in your `src/type.d.ts`:
32
+
33
+ ```typescript
34
+ declare module '@tiddlygit/tiddlywiki' {
35
+ export * from 'tiddlywiki';
36
+ }
37
+ ```
26
38
 
39
+ ## Development
40
+
41
+ Firstly, Install eslint using npm:
42
+
43
+ ```sh
44
+ npm i
27
45
  ```
46
+
47
+ You can add new `*.d.ts` file to contain your types:
48
+
49
+ 1. use `declare module 'tiddlywiki' { }` to wrap all your types.
50
+ 1. don't forget to `export` all your types.
51
+ 1. to add type for global variable, add `global { }` inside that `declare module 'tiddlywiki' { }`, like `global { var $tw: I$TW; }`
52
+
53
+ And add `import './xxx';` in the `index.d.ts` file.
54
+
55
+ To rapid prototype the type, just right click a type to open `.d.ts` file in the `node_modules`, and try create new file there, and copy to this repo after a success.
package/package.json CHANGED
@@ -2,16 +2,39 @@
2
2
  "description": "Types for tiddlywiki",
3
3
  "license": "MIT",
4
4
  "name": "tw5-typed",
5
- "version": "0.0.3",
5
+ "version": "0.0.7",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
+ "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
+ "bugs": {
9
+ "url": "https://github.com/tiddly-gittly/tw5-typed/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/tiddly-gittly/tw5-typed.git"
14
+ },
7
15
  "types": "src/index.d.ts",
8
16
  "files": [
9
17
  "src/"
10
18
  ],
11
- "author": "",
12
- "scripts": {},
19
+ "scripts": {
20
+ "prepublishOnly": "npx tsc --noEmit"
21
+ },
13
22
  "devDependencies": {
14
- "typescript": "^4.5.5"
23
+ "@typescript-eslint/eslint-plugin": "5.10.2",
24
+ "@typescript-eslint/parser": "5.10.2",
25
+ "typescript": "4.5.5",
26
+ "eslint": "8.8.0",
27
+ "eslint-config-prettier": "8.3.0",
28
+ "eslint-config-standard": "17.0.0-1",
29
+ "eslint-config-standard-with-typescript": "21.0.1",
30
+ "eslint-import-resolver-alias": "1.1.2",
31
+ "eslint-import-resolver-typescript": "2.5.0",
32
+ "eslint-plugin-import": "2.25.4",
33
+ "eslint-plugin-node": "11.1.0",
34
+ "eslint-plugin-prettier": "4.0.0",
35
+ "eslint-plugin-typescript-sort-keys": "2.1.0",
36
+ "eslint-plugin-unicorn": "40.1.0",
37
+ "prettier": "2.5.1"
15
38
  },
16
39
  "dependencies": {}
17
40
  }
@@ -1,40 +1,42 @@
1
- export type SourceIterator = (tiddler: Object, title: string) => void;
2
- export interface ISearchOptions {
3
- /** an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title) */
4
- source?: (iter: SourceIterator) => void;
5
- /** An array of tiddler titles to exclude from the search */
6
- exclude?: string[];
7
- /** If true returns tiddlers that do not contain the specified string */
8
- invert?: boolean;
9
- /** If true forces a case sensitive search */
10
- caseSensitive?: boolean;
11
- /** If specified, restricts the search to the specified field, or an array of field names */
12
- field?: string | string[];
13
- /** If true, forces all but regexp searches to be anchored to the start of text */
14
- anchored?: boolean;
15
- /** If true, the field options are inverted to specify the fields that are not to be searched */
16
- excludeField?: boolean;
17
- /** searches for literal string */
18
- literal?: boolean;
19
- /** same as literal except runs of whitespace are treated as a single space */
20
- whitespace?: boolean;
21
- /** (default) treats search string as a list of tokens, and matches if all tokens are found, regardless of adjacency or ordering */
22
- words?: boolean;
23
- }
1
+ declare module 'tiddlywiki' {
2
+ export type SourceIterator = (tiddler: Object, title: string) => void;
3
+ export interface ISearchOptions {
4
+ /** an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title) */
5
+ source?: (iter: SourceIterator) => void;
6
+ /** An array of tiddler titles to exclude from the search */
7
+ exclude?: string[];
8
+ /** If true returns tiddlers that do not contain the specified string */
9
+ invert?: boolean;
10
+ /** If true forces a case sensitive search */
11
+ caseSensitive?: boolean;
12
+ /** If specified, restricts the search to the specified field, or an array of field names */
13
+ field?: string | string[];
14
+ /** If true, forces all but regexp searches to be anchored to the start of text */
15
+ anchored?: boolean;
16
+ /** If true, the field options are inverted to specify the fields that are not to be searched */
17
+ excludeField?: boolean;
18
+ /** searches for literal string */
19
+ literal?: boolean;
20
+ /** same as literal except runs of whitespace are treated as a single space */
21
+ whitespace?: boolean;
22
+ /** (default) treats search string as a list of tokens, and matches if all tokens are found, regardless of adjacency or ordering */
23
+ words?: boolean;
24
+ }
24
25
 
25
- export interface IFilterOperatorParamOperator {
26
- /** the name of the filter operator specified in the WikiText; */
27
- operator: string;
28
- /** the operand for the filter step (as a string; if the filter specified it in angle brackets or braces, the text reference or letiable name will have already been resolved); */
29
- operand: string;
30
- /** (optional) a string containing a single exclamation mark if the filter operator is to be negated; */
31
- prefix?: string;
32
- /** (optional) a string containing an additional filter argument (typically a tiddler field name) following the filter name (separated by a colon in the filter syntax); */
33
- suffix?: string;
34
- /** multiple suffix
35
- * for example, in `search:<field list>:<flag list>[<operand>]`, you will get `<field list>` as suffixes[0], and `<flag list>` as suffixes[1]
36
- */
37
- suffixes?: string[][];
38
- /** (optional, deprecated) used instead of `operand` if the filter operand is a regexp. */
39
- regexp?: string;
26
+ export interface IFilterOperatorParamOperator {
27
+ /** the name of the filter operator specified in the WikiText; */
28
+ operator: string;
29
+ /** the operand for the filter step (as a string; if the filter specified it in angle brackets or braces, the text reference or letiable name will have already been resolved); */
30
+ operand: string;
31
+ /** (optional) a string containing a single exclamation mark if the filter operator is to be negated; */
32
+ prefix?: string;
33
+ /** (optional) a string containing an additional filter argument (typically a tiddler field name) following the filter name (separated by a colon in the filter syntax); */
34
+ suffix?: string;
35
+ /** multiple suffix
36
+ * for example, in `search:<field list>:<flag list>[<operand>]`, you will get `<field list>` as suffixes[0], and `<flag list>` as suffixes[1]
37
+ */
38
+ suffixes?: string[][];
39
+ /** (optional, deprecated) used instead of `operand` if the filter operand is a regexp. */
40
+ regexp?: string;
41
+ }
40
42
  }
package/src/index.d.ts CHANGED
@@ -1,11 +1,6 @@
1
- import { I$TW } from './tw';
2
- export * from './tw';
3
- export * from './filter-operator';
1
+ import './tw';
2
+ import './filter-operator';
4
3
 
5
- declare module 'tiddlywiki' {}
6
-
7
- declare module '@tiddlygit/tiddlywiki' {}
8
-
9
- declare global {
10
- var $tw: I$TW;
4
+ declare module '@tiddlygit/tiddlywiki' {
5
+ export * from 'tiddlywiki';
11
6
  }
package/src/tw.d.ts CHANGED
@@ -1,45 +1,186 @@
1
- export interface ITiddler {
2
- cache: ITiddlerCache;
3
- fields: ITiddlerFields;
4
- }
1
+ declare module 'tiddlywiki' {
2
+ export interface ITiddler {
3
+ constructor(...fields: (Record<string, unknown> | ITiddler)[]);
4
+ readonly cache: ITiddlerCache;
5
+ readonly fields: ITiddlerFields;
6
+ // static fieldModules: IModule;
7
+ hasField(field: string): boolean;
8
+ isEqual(tiddler: ITiddler, excludeFields: string[]): boolean;
9
+ }
5
10
 
6
- export interface ITiddlerFields {
7
- created: string;
8
- list: string[];
9
- modified: string;
10
- tags: string[];
11
- text: string;
12
- title: string;
13
- type: string;
14
- }
11
+ export interface ITiddlerFields {
12
+ readonly created: Date;
13
+ readonly list: string[];
14
+ readonly modified: Date;
15
+ readonly tags: string[];
16
+ readonly text: string;
17
+ readonly title: string;
18
+ readonly type: string;
19
+ readonly color: string;
20
+ readonly [anyKey: string]: unknown;
21
+ }
15
22
 
16
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
17
- export interface ITiddlerCache {}
18
-
19
- /**
20
- * filepath: '/Users/linonetwo/xxxx/wiki/Meme-of-LinOnetwo/tiddlers/tiddlerTitle.tid',
21
- * hasMetaFile: false
22
- * tiddlerTitle: string,
23
- * type: 'application/x-tiddler',
24
- */
25
- export interface IBootFilesIndexItem {
26
- filepath: string;
27
- hasMetaFile: boolean;
28
- tiddlerTitle: string;
29
- type: string;
30
- }
31
- /**
32
- * Record<tiddlerTitle, IBootFilesIndexItem>
33
- */
34
- export type IBootFilesIndex = Partial<Record<string, IBootFilesIndexItem>>;
35
-
36
- export interface I$TW {
37
- boot: { argv: string[]; files: IBootFilesIndex; startup: (options: { callback?: () => unknown }) => void };
38
- hooks: { addHook: (hookName: string, callback: (...arguments_: any[]) => unknown) => void };
39
- wiki: {
40
- getTiddler: (title: string) => ITiddler | undefined;
41
- getTiddlers: () => ITiddler[];
42
- };
43
- utils: Record<string, any>;
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
24
+ export interface ITiddlerCache {}
25
+
26
+ /**
27
+ * filepath: '/Users/linonetwo/xxxx/wiki/Meme-of-LinOnetwo/tiddlers/tiddlerTitle.tid',
28
+ * hasMetaFile: false
29
+ * tiddlerTitle: string,
30
+ * type: 'application/x-tiddler',
31
+ */
32
+ export interface IBootFilesIndexItem {
33
+ filepath: string;
34
+ hasMetaFile: boolean;
35
+ tiddlerTitle: string;
36
+ type: string;
37
+ }
38
+ /**
39
+ * Record<tiddlerTitle, IBootFilesIndexItem>
40
+ */
41
+ export type IBootFilesIndex = Partial<Record<string, IBootFilesIndexItem>>;
42
+
43
+ export interface IModule {
44
+ moduleType: string;
45
+ definition: unknown;
46
+ exports: object | null;
47
+ }
48
+
49
+ export interface TiddlyWiki {
50
+ boot: {
51
+ argv: string[];
52
+ files: IBootFilesIndex;
53
+ startup(options: { callback?: () => unknown }): void;
54
+ /** Default boot tasks */
55
+ tasks: {
56
+ trapErrors: boolean;
57
+ readBrowserTiddlers: boolean;
58
+ };
59
+ logMessages: string[];
60
+ log(str: string): void;
61
+ };
62
+
63
+ /** Broswer features, if tw isn't running on a browser environment, the value will be `null` */
64
+ browser: null | object;
65
+ /** NodeJS features, if tw isn't running on a NodeJS environment, the value will be `null` */
66
+ node: null | object;
67
+ nodeWebKit: null | object;
68
+
69
+ /**
70
+ * Information about each module is kept in an object with these members:
71
+ *
72
+ * * moduleType: type of module
73
+ * * definition: object, function or string defining the module; see below
74
+ * * exports: exports of the module, filled in after execution
75
+ *
76
+ * The `definition` can be of several types:
77
+ *
78
+ * * An object can be used to directly specify the exports of the module
79
+ * * A function with the arguments `module,require,exports` that returns `exports`
80
+ * * A string function body with the same arguments
81
+ *
82
+ * Each moduleInfo object is stored in two hashmaps: $tw.modules.titles and $tw.modules.types. The first is indexed by title and the second is indexed by type and then title
83
+ */
84
+ modules: {
85
+ /** hashmap by module name of moduleInfo */
86
+ titles: Record<string, IModule>;
87
+ /** hashmap by module type and then name of moduleInfo */
88
+ types: Record<string, Record<string, IModule>>;
89
+ /**
90
+ * Define a JavaScript tiddler module for later execution
91
+ * @param {string} moduleName name of module being defined
92
+ * @param {string} moduleType type of module
93
+ * @param {unknown} definition module definition; see discussion above
94
+ */
95
+ define(moduleName: string, moduleType: string, definition: unknown): void;
96
+ };
97
+
98
+ /** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
99
+ preloadTiddlers: Record<string, Record<string, unknown>>;
100
+ /** Convenience function for pushing a tiddler onto the preloading array */
101
+ preloadTiddler(fields: Record<string, unknown>): void;
102
+ /** Convenience function for pushing an array of tiddlers onto the preloading array */
103
+ preloadTiddlerArray(fieldsArray: Record<string, unknown>[]): void;
104
+
105
+ hooks: {
106
+ addHook: (hookName: string, callback: (...arguments_: any[]) => unknown) => void;
107
+ };
108
+ wiki: {
109
+ getTiddler: (title: string) => ITiddler | undefined;
110
+ /**
111
+ * Get full list of tiddler titles in the wiki
112
+ */
113
+ getTiddlers: () => string[];
114
+ };
115
+ utils: {
116
+ /** Check if an object has a property. */
117
+ hop(object: object, property: string): boolean;
118
+ /** Determine if a value is an array. */
119
+ isArray(value: unknown): boolean;
120
+ /** Check if an array is equal by value and by reference. */
121
+ isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
122
+ /**
123
+ * Push entries onto an array, removing them first if they already exist in the array
124
+ *
125
+ * * array: array to modify (assumed to be free of duplicates)
126
+ * * value: a single value to push or an array of values to push
127
+ */
128
+ pushTop(array: unknown[], value: unknown): void;
129
+ /** Determine if a value is a date */
130
+ isDate(value: unknown): void;
131
+ /**
132
+ * Iterate through all the own properties of an object or array.
133
+ *
134
+ * Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.
135
+ * */
136
+ each<T = object | unknown[]>(object: T, callback: (element?: unknown, index?: string | number, object?: T) => boolean | void);
137
+ /**
138
+ * Helper for making DOM elements
139
+ * Options include:
140
+ * * namespace:
141
+ * * attributes: hashmap of attribute values
142
+ * * style: hashmap of styles
143
+ * * text: text to add as a child node
144
+ * * children: array of further child nodes
145
+ * * innerHTML: optional HTML for element
146
+ * * class: class name(s)
147
+ * * document: defaults to current document
148
+ * * eventListeners: array of event listeners (this option won't work until `$tw.utils.addEventListeners()` has been loaded)
149
+ *
150
+ * @param {string} tag tag name
151
+ * @param {{
152
+ * namespace?: string;
153
+ * attributes?: Record<string, unknown>;
154
+ * style?: Record<string, string>;
155
+ * text?: string;
156
+ * children?: Element[];
157
+ * innerHTML?: string;
158
+ * class?: string;
159
+ * document?: Document;
160
+ * eventListeners?: EventListener[];
161
+ * }} options
162
+ * @returns {Element}
163
+ */
164
+ domMaker(
165
+ tag: string,
166
+ options: {
167
+ namespace?: string;
168
+ attributes?: Record<string, unknown>;
169
+ style?: Record<string, string>;
170
+ text?: string;
171
+ children?: Element[];
172
+ innerHTML?: string;
173
+ class?: string;
174
+ document?: Document;
175
+ eventListeners?: EventListener[];
176
+ },
177
+ ): Element;
178
+ };
179
+ }
180
+
181
+ export function TiddlyWiki(): TiddlyWiki;
182
+
183
+ global {
184
+ const $tw: TiddlyWiki;
185
+ }
44
186
  }
45
- export function TiddlyWiki(): I$TW;
@@ -0,0 +1,13 @@
1
+ declare class variablesConstructor {
2
+
3
+ }
4
+
5
+ export class Widget {
6
+ constructor(parseTreeNode: any, options: any);
7
+ initialize: (parseTreeNode: any, options: any) => void;
8
+ parseTreeNode: any;
9
+ wiki: any;
10
+ parentWidget?: Widget;
11
+ variablesConstructor: variablesConstructor;
12
+ variables: any;
13
+ }