Skip to content

Commit b4655d2

Browse files
author
Giuseppe Verni
committed
Add .d.ts files
1 parent 40257d6 commit b4655d2

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

dist/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { SegmentedMessage } from './libs/SegmentedMessage';
2+
export { SegmentedMessage };

dist/libs/EncodedChar.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Encoded Character Classes
3+
* Utility classes to represent a character in a given encoding.
4+
*/
5+
declare class EncodedChar {
6+
raw: string;
7+
codeUnits: number[];
8+
isGSM7: boolean;
9+
encoding: 'GSM-7' | 'UCS-2';
10+
constructor(char: string, encoding: 'GSM-7' | 'UCS-2');
11+
codeUnitSizeInBits(): number;
12+
sizeInBits(): number;
13+
}
14+
export default EncodedChar;

dist/libs/Segment.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import EncodedChar from './EncodedChar';
2+
/**
3+
* Segment Class
4+
* A modified array representing one segment and add some helper functions
5+
*/
6+
declare class Segment extends Array {
7+
hasTwilioReservedBits: boolean;
8+
hasUserDataHeader: boolean;
9+
constructor(withUserDataHeader?: boolean);
10+
sizeInBits(): number;
11+
messageSizeInBits(): number;
12+
freeSizeInBits(): number;
13+
addHeader(): EncodedChar[];
14+
}
15+
export default Segment;

dist/libs/SegmentedMessage.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import Segment from './Segment';
2+
import EncodedChar from './EncodedChar';
3+
declare type SmsEncoding = 'GSM-7' | 'UCS-2';
4+
declare type EncodedChars = Array<EncodedChar>;
5+
/**
6+
* Class representing a segmented SMS
7+
*/
8+
export declare class SegmentedMessage {
9+
encoding: SmsEncoding | 'auto';
10+
segments: Segment[];
11+
graphemes: string[];
12+
encodingName: SmsEncoding;
13+
numberOfUnicodeScalars: number;
14+
numberOfCharacters: number;
15+
/**
16+
*
17+
* Create a new segmented message from a string
18+
*
19+
* @param {string} message Body of the message
20+
* @param {boolean} [encoding] Optional: encoding. It can be 'GSM-7', 'UCS-2', 'auto'. Default value: 'auto'
21+
* @property {number} numberOfUnicodeScalars Number of Unicode Scalars (i.e. unicode pairs) the message is made of
22+
*
23+
*/
24+
constructor(message: string, encoding?: SmsEncoding | 'auto');
25+
/**
26+
* Internal method to check if the message has any non-GSM7 characters
27+
*
28+
* @param {string[]} graphemes Message body
29+
* @returns {boolean} True if there are non-GSM-7 characters
30+
* @private
31+
*/
32+
_hasAnyUCSCharacters(graphemes: string[]): boolean;
33+
/**
34+
* Internal method used to build message's segment(s)
35+
*
36+
* @param {object[]} encodedChars Array of EncodedChar
37+
* @returns {object[]} Array of Segment
38+
* @private
39+
*/
40+
_buildSegments(encodedChars: EncodedChars): Segment[];
41+
/**
42+
* Return the encoding of the message segment
43+
*
44+
* @returns {string} Encoding for the message segment(s)
45+
*/
46+
getEncodingName(): string;
47+
/**
48+
* Internal method to create an array of EncodedChar from a string
49+
*
50+
* @param {string[]} graphemes Array of graphemes representing the message
51+
* @returns {object[]} Array of EncodedChar
52+
* @private
53+
*/
54+
_encodeChars(graphemes: string[]): EncodedChars;
55+
/**
56+
* @return {number} Total size of the message in bits (including User Data Header if present)
57+
*/
58+
get totalSize(): number;
59+
/**
60+
* @return {number} Total size of the message in bits (excluding User Data Header if present)
61+
*/
62+
get messageSize(): number;
63+
/**
64+
*
65+
* @return {number} Number of segments
66+
*/
67+
get segmentsCount(): number;
68+
}
69+
export {};

dist/libs/UnicodeToGSM.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const UnicodeToGsm: Record<string, Array<number>>;
2+
export default UnicodeToGsm;

dist/libs/UserDataHeader.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare class UserDataHeader {
2+
isReservedChar: boolean;
3+
isUserDataHeader: boolean;
4+
constructor();
5+
static codeUnitSizeInBits(): number;
6+
sizeInBits(): number;
7+
}
8+
export default UserDataHeader;

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4+
"declaration": true,
45
"module": "commonjs",
56
"sourceMap": true,
67
"outDir": "dist",

0 commit comments

Comments
 (0)