@ceeblue/web-utils 1.2.0 → 1.3.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/README.md CHANGED
@@ -1,21 +1,65 @@
1
- # Ceeblue web framework
1
+ [Usage](#usage) | [Building locally](#building-locally) | [Documentation](#documentation) | [Contribution](#contribution) | [License](#license)
2
2
 
3
- This is a web framework for CeeblueTV's web libraries. It is a collection of tools and utilities that are used across all of CeeblueTV's web projects.
3
+ # Ceeblue Web Utilities
4
4
 
5
- ## Installation
5
+ This is a Web base compoments for CeeblueTV's web libraries : a collection of tools and utilities used across all of CeeblueTV's web projects.
6
6
 
7
- You can install the package using npm:
7
+ ## Usage
8
8
 
9
+ Add the library as a dependency to your npm project using:
9
10
  ```bash
10
11
  npm install @ceeblue/web-utils
11
12
  ```
13
+ Then [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) the library into your project, for example:
14
+ ```javascript
15
+ import { Util, ILog } from '@ceeblue/web-utils';
16
+ ```
17
+ > 💡 **TIP**
18
+ >
19
+ > If your project uses [TypeScript](https://www.typescriptlang.org/), it is recommended to set `"target": "ES6"` in your configuration to align with our usage of ES6 features and ensures that your build will succeed (for those requiring a backwards-compatible [UMD](https://github.com/umdjs/umd) version, a [local build](#building-locally) is advised).
20
+ > Then Defining the compiler option `"moduleResolution": "Node"` in **tsconfig.json** helps with import errors by ensuring that TypeScript uses the correct strategy for resolving imports based on the targeted Node.js version.
21
+ > ```json
22
+ > {
23
+ > "compilerOptions": {
24
+ > "target": "ES6",
25
+ > "moduleResolution": "Node"
26
+ > }
27
+ > }
28
+ > ```
29
+
30
+ ## Building locally
12
31
 
13
- Or manually add it to your `package.json` file:
32
+ 1. [Clone](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository) this repository
33
+ 2. Enter the `webr-utils` folder and run `npm install` to install packages dependencies.
34
+ 3. Execute `npm run build`. The output will be five files placed in the **/dist/** folder:
35
+ - **web-utils.d.ts** Typescript definitions file
36
+ - **web-utils.js**: Bundled JavaScript library
37
+ - **web-utils.js.map**: Source map that associates the bundled library with the original source files
38
+ - **web-utils.min.js** Minified version of the library, optimized for size
39
+ - **web-utils.min.js.map** Source map that associates the minified library with the original source files
14
40
 
15
- ```json
16
- {
17
- "dependencies": {
18
- "@ceeblue/web-utils": "latest"
19
- }
20
- }
21
41
  ```
42
+ git clone https://github.com/CeeblueTV/web-utils.git
43
+ cd web-utils
44
+ npm install
45
+ npm run build
46
+ ```
47
+
48
+ ## Documentation
49
+
50
+ This monorepo also contains built-in documentation about the APIs in the library, which can be built using the following npm command:
51
+ ```
52
+ npm run build:docs
53
+ ```
54
+ You can access the documentation by opening the index.html file in the docs folder with your browser (`./docs/index.html`), or if you have installed and started the [http-server package](https://www.npmjs.com/package/http-server) by navigating to:
55
+ ```
56
+ http://localhost:8080/docs/
57
+ ```
58
+
59
+ ## Contribution
60
+
61
+ All contributions are welcome. Please see [our contribution guide](/CONTRIBUTING.md) for details.
62
+
63
+ ## License
64
+
65
+ By contributing code to this project, you agree to license your contribution under the [GNU Affero General Public License](/LICENSE).
@@ -1,11 +1,3 @@
1
- /**
2
- * Copyright 2024 Ceeblue B.V.
3
- * This file is part of https://github.com/CeeblueTV/web-utils which is released under GNU Affero General Public License.
4
- * See file LICENSE or go to https://spdx.org/licenses/AGPL-3.0-or-later.html for full license details.
5
- */
6
- /**
7
- * BinaryReader allows to read binary data
8
- */
9
1
  declare class BinaryReader {
10
2
  private _data;
11
3
  private _size;
@@ -24,13 +16,14 @@ declare class BinaryReader {
24
16
  read16(): number;
25
17
  read24(): number;
26
18
  read32(): number;
19
+ read64(): number;
27
20
  readFloat(): number;
28
21
  readDouble(): number;
29
22
  read7Bit(bytes?: number): number;
30
23
  readString(): string;
31
24
  readHex(size: number): string;
32
25
  /**
33
- * Read bytes, to convert bytes to string use String.fromCharCode(...reader.read(size))
26
+ * Read bytes, to convert bytes to string use String.fromCharCode(...reader.read(size)) or Util.stringify
34
27
  * @param {UInt32} size
35
28
  */
36
29
  read(size?: number): Uint8Array;
@@ -56,14 +49,19 @@ declare class BinaryWriter {
56
49
  size(): number;
57
50
  next(count?: number): BinaryWriter;
58
51
  clear(size?: number): BinaryWriter;
59
- write(data: string | ArrayLike<number>): BinaryWriter;
52
+ /**
53
+ * Write binary data
54
+ * @param data
55
+ */
56
+ write(data: ArrayLike<number>): BinaryWriter;
60
57
  write8(value: number): BinaryWriter;
61
58
  write16(value: number): BinaryWriter;
62
59
  write24(value: number): BinaryWriter;
63
60
  write32(value: number): BinaryWriter;
61
+ write64(value: number): BinaryWriter;
64
62
  writeFloat(value: number): BinaryWriter;
65
63
  writeDouble(value: number): BinaryWriter;
66
- write7Bit(value: number, bytes?: number): BinaryWriter;
64
+ write7Bit(value: number): BinaryWriter;
67
65
  writeString(value: string): BinaryWriter;
68
66
  writeHex(value: string): BinaryWriter;
69
67
  reserve(size: number): BinaryWriter;
@@ -124,11 +122,11 @@ type Params = {
124
122
  * Type of connection
125
123
  */
126
124
  declare enum Type {
127
- HESP = "hesp",
128
- WEBRTS = "webrts",
129
- WEBRTC = "webrtc",
130
- META = "meta",
131
- DATA = "data"
125
+ HESP = "HESP",
126
+ WEBRTS = "WebRTS",
127
+ WEBRTC = "WebRTC",
128
+ META = "Meta",
129
+ DATA = "Data"
132
130
  }
133
131
  /**
134
132
  * Some connection utility functions
@@ -593,13 +591,15 @@ declare function objectEntries(value: any): [string, any][];
593
591
  * @param obj Any objects, strings, exceptions, errors, or number
594
592
  * @param params.space `''`, allows to configure space in the string representation
595
593
  * @param params.decimal `2`, allows to choose the number of decimal to display in the string representation
596
- * @param params.recursive `false`, allows to serialize recursively every object value, beware if a value refers to a already parsed value an infinite loop will occur.
594
+ * @param params.recursive `false`, allows to serialize recursively every object value, beware if a value refers to a already parsed value an infinite loop will occur
595
+ * @param params.noBin `false`, when set skip binary encoding and write inplace a bin-length information
597
596
  * @returns the final string representation
598
597
  */
599
598
  declare function stringify(obj: any, params?: {
600
599
  space?: string;
601
600
  decimal?: number;
602
601
  recursive?: number;
602
+ noBin?: boolean;
603
603
  }): string;
604
604
  /**
605
605
  * Encode a string to a binary representation
@@ -611,18 +611,36 @@ declare function toBin(value: string): Uint8Array;
611
611
  * Execute a promise in a safe way with a timeout if caller doesn't resolve it in the accurate time
612
612
  */
613
613
  declare function safePromise<T>(timeout: number, promise: Promise<T>): Promise<unknown>;
614
+ /**
615
+ * Wait in milliseconds, requires a call with await keyword!
616
+ */
617
+ declare function sleep(ms: number): Promise<unknown>;
618
+ /**
619
+ * fetch help method with few usefull fix:
620
+ * - throw an string exception if response code is not 200 with the text of the response or uses statusText
621
+ */
622
+ declare function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
623
+ /**
624
+ * Extension parser
625
+ * @param path path to parse
626
+ * @returns the extension
627
+ */
628
+ declare function parseExtension(path: string): string;
614
629
 
615
630
  declare const Util_EMPTY_FUNCTION: typeof EMPTY_FUNCTION;
631
+ declare const Util_fetch: typeof fetch;
616
632
  declare const Util_objectEntries: typeof objectEntries;
617
633
  declare const Util_objectFrom: typeof objectFrom;
618
634
  declare const Util_options: typeof options;
635
+ declare const Util_parseExtension: typeof parseExtension;
619
636
  declare const Util_safePromise: typeof safePromise;
637
+ declare const Util_sleep: typeof sleep;
620
638
  declare const Util_stringify: typeof stringify;
621
639
  declare const Util_time: typeof time;
622
640
  declare const Util_timeOrigin: typeof timeOrigin;
623
641
  declare const Util_toBin: typeof toBin;
624
642
  declare namespace Util {
625
- export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_safePromise as safePromise, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin };
643
+ export { Util_EMPTY_FUNCTION as EMPTY_FUNCTION, Util_fetch as fetch, Util_objectEntries as objectEntries, Util_objectFrom as objectFrom, Util_options as options, Util_parseExtension as parseExtension, Util_safePromise as safePromise, Util_sleep as sleep, Util_stringify as stringify, Util_time as time, Util_timeOrigin as timeOrigin, Util_toBin as toBin };
626
644
  }
627
645
 
628
646
  /**
@@ -676,6 +694,8 @@ declare class WebSocketReliable extends EventEmitter {
676
694
  * binaryType, fix binary type to arrayBuffer
677
695
  */
678
696
  get binaryType(): BinaryType;
697
+ get recvByteRate(): number;
698
+ get sendByteRate(): number;
679
699
  /**
680
700
  * url of connection
681
701
  */
@@ -714,6 +734,8 @@ declare class WebSocketReliable extends EventEmitter {
714
734
  private _queueing;
715
735
  private _queueingBytes;
716
736
  private _ws?;
737
+ private _recvByteRate;
738
+ private _sendByteRate;
717
739
  /**
718
740
  * Create a WebSocketReliable object, and open it if an url is passed in argument
719
741
  * @param url URL of the WebSocket endpoint or null to start the connection later
@@ -741,6 +763,7 @@ declare class WebSocketReliable extends EventEmitter {
741
763
  * @param error the error reason if is not a proper close
742
764
  */
743
765
  close(error?: string): void;
766
+ private _send;
744
767
  }
745
768
 
746
769
  /**