Skip to content

Commit

Permalink
rename length -> stringLength
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfheij-sil committed Feb 21, 2024
1 parent c0d36b8 commit 36479d8
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 152 deletions.
2 changes: 1 addition & 1 deletion lib/platform-bible-utils/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-utils/dist/index.cjs.map

Large diffs are not rendered by default.

153 changes: 95 additions & 58 deletions lib/platform-bible-utils/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,63 +404,75 @@ export declare function getAllObjectFunctionNames(obj: {
*/
export declare function createSyncProxyForAsyncObject<T extends object>(getObject: (args?: unknown[]) => Promise<T>, objectToProxy?: Partial<T>): T;
/**
* Finds the Unicode code point at the given index. This function handles Unicode code points
* instead of UTF-16 character codes.
* This function mirrors the `at` function from the JavaScript Standard String object. It handles
* Unicode code points instead of UTF-16 character codes.
*
* Finds the Unicode code point at the given index.
*
* @param string String to index
* @param index Position of the character to be returned in range of -length(string) to
* length(string)
* @returns New string consisting of the Unicode code point located at the specified
* offset, undefined if index is out of bounds
* length(string)
* @returns New string consisting of the Unicode code point located at the specified offset,
* undefined if index is out of bounds
*/
export declare function at(string: string, index: number): string | undefined;
/**
* Returns a new string consisting of the single UTF-16 code unit at the given index.
* This function handles Unicode code points instead of UTF-16 character codes.
* This function mirrors the `charAt` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Returns a new string consisting of the single unicode code point at the given index.
*
* @param string String to index
* @param index Position of the string character to be returned, in the range of 0 to
* length(string)-1
* @returns New string consisting of the Unicode code point located at the specified
* offset, empty string if index is out of bounds
* @returns New string consisting of the Unicode code point located at the specified offset, empty
* string if index is out of bounds
*/
export declare function charAt(string: string, index: number): string;
/**
* This function mirrors the `codePointAt` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Returns a non-negative integer that is the Unicode code point value of the character starting at
* the given index. This function handles Unicode code points instead of UTF-16 character codes.
* the given index.
*
* @param string String to index
* @param index Position of the string character to be returned, in the range of 0 to
* length(string)-1
* @returns Non-negative integer representing the code point value of the
* character at the given index, or undefined if there is no element at that position
* @returns Non-negative integer representing the code point value of the character at the given
* index, or undefined if there is no element at that position
*/
export declare function codePointAt(string: string, index: number): number | undefined;
/**
* Determines whether a string ends with the characters of this string. This function handles
* Unicode code points instead of UTF-16 character codes.
* This function mirrors the `endsWith` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Determines whether a string ends with the characters of this string.
*
* @param string String to search through
* @param searchString Characters to search for at the end of the string
* @param endPosition End position where searchString is expected to be
* found. Default is `length(string)`
* @param endPosition End position where searchString is expected to be found. Default is
* `length(string)`
* @returns True if it ends with searchString, false if it does not
*/
export declare function endsWith(string: string, searchString: string, endPosition?: number): boolean;
/**
* Performs a case-sensitive search to determine if searchString is found in string. This function
* This function mirrors the `includes` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Performs a case-sensitive search to determine if searchString is found in string.
*
* @param string String to search through
* @param searchString String to search for
* @param position Position within the string to start searching for searchString.
* Default is `0`
* @param position Position within the string to start searching for searchString. Default is `0`
* @returns True if search string is found, false if it is not
*/
export declare function includes(string: string, searchString: string, position?: number): boolean;
/**
* Returns the index of the first occurrence of a given string. This function handles Unicode code
* points instead of UTF-16 character codes.
* This function mirrors the `indexOf` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Returns the index of the first occurrence of a given string.
*
* @param string String to search through
* @param searchString The string to search for
Expand All @@ -469,18 +481,32 @@ export declare function includes(string: string, searchString: string, position?
*/
export declare function indexOf(string: string, searchString: string, position?: number | undefined): number;
/**
* This function mirrors the `lastIndexOf` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Searches this string and returns the index of the last occurrence of the specified substring.
* This function handles Unicode code points instead of UTF-16 character codes.
*
* @param string String to search through
* @param searchString Substring to search for
* @param position The index at which to begin searching. If omitted, the search begins at the end
* of the string. Default is `undefined`
* of the string. Default is `undefined`
* @returns Index of the last occurrence of searchString found, or -1 if not found.
*/
export declare function lastIndexOf(string: string, searchString: string, position?: number): number;
declare function length$1(string: string): number;
/**
* This function mirrors the `length` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Returns the length of a string.
*
* @param string String to return the length for
* @returns Number that is length of the starting string
*/
export declare function stringLength(string: string): number;
/**
* This function mirrors the `normalize` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Returns the Unicode Normalization Form of this string.
*
* @param string The starting string
Expand All @@ -489,34 +515,41 @@ declare function length$1(string: string): number;
*/
export declare function normalize(string: string, form: "NFC" | "NFD" | "NFKC" | "NFKD" | "none"): string;
/**
* Pads this string with another string (multiple times, if needed) until the resulting string
* reaches the given length. The padding is applied from the end of this string. This function
* This function mirrors the `padEnd` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Pads this string with another string (multiple times, if needed) until the resulting string
* reaches the given length. The padding is applied from the end of this string.
*
* @param string String to add padding too
* @param targetLength The length of the resulting string once the starting string has been
* padded. If value is less than or equal to length(string), then string is returned as is.
* @param padString The string to pad the current string with. If padString is too
* long to stay within targetLength, it will be truncated. Default is `" "`
* @param targetLength The length of the resulting string once the starting string has been padded.
* If value is less than or equal to length(string), then string is returned as is.
* @param padString The string to pad the current string with. If padString is too long to stay
* within targetLength, it will be truncated. Default is `" "`
* @returns String with appropriate padding at the end
*/
export declare function padEnd(string: string, targetLength: number, padString?: string): string;
/**
* Pads this string with another string (multiple times, if needed) until the resulting string
* reaches the given length. The padding is applied from the start of this string. This function
* This function mirrors the `padStart` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Pads this string with another string (multiple times, if needed) until the resulting string
* reaches the given length. The padding is applied from the start of this string.
*
* @param string String to add padding too
* @param targetLength The length of the resulting string once the starting string has been
* padded. If value is less than or equal to length(string), then string is returned as is.
* @param padString The string to pad the current string with. If padString is too
* long to stay within the targetLength, it will be truncated from the end. Default is `" "`
* @param targetLength The length of the resulting string once the starting string has been padded.
* If value is less than or equal to length(string), then string is returned as is.
* @param padString The string to pad the current string with. If padString is too long to stay
* within the targetLength, it will be truncated from the end. Default is `" "`
* @returns String with of specified targetLength with padString applied from the start
*/
export declare function padStart(string: string, targetLength: number, padString?: string): string;
/**
* This function mirrors the `slice` function from the JavaScript Standard String object. It handles
* Unicode code points instead of UTF-16 character codes.
*
* Extracts a section of this string and returns it as a new string, without modifying the original
* string. This function handles Unicode code points instead of UTF-16 character codes.
* string.
*
* @param string The starting string
* @param indexStart The index of the first character to include in the returned substring.
Expand All @@ -525,35 +558,41 @@ export declare function padStart(string: string, targetLength: number, padString
*/
export declare function slice(string: string, indexStart: number, indexEnd?: number): string;
/**
* Takes a pattern and divides the string into an ordered list of substrings by searching for the
* pattern, puts these substrings into an array, and returns the array. This function handles
* This function mirrors the `split` function from the JavaScript Standard String object. It handles
* Unicode code points instead of UTF-16 character codes.
*
* Takes a pattern and divides the string into an ordered list of substrings by searching for the
* pattern, puts these substrings into an array, and returns the array.
*
* @param string The string to split
* @param separator The pattern describing where each split should occur
* @param splitLimit Limit on the number of substrings to be included in the array. Splits
* the string at each occurrence of specified separator, but stops when limit entries have been
* placed in the array.
* @returns An array of strings, split at each point where separator occurs
* in the starting string. Returns undefined if separator is not found in string.
* @param splitLimit Limit on the number of substrings to be included in the array. Splits the
* string at each occurrence of specified separator, but stops when limit entries have been placed
* in the array.
* @returns An array of strings, split at each point where separator occurs in the starting string.
* Returns undefined if separator is not found in string.
*/
export declare function split(string: string, separator: string | RegExp, splitLimit?: number): string[];
/**
* This function mirrors the `startsWith` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Determines whether the string begins with the characters of a specified string, returning true or
* false as appropriate. This function handles Unicode code points instead of UTF-16 character
* codes.
* false as appropriate.
*
* @param string String to search through
* @param searchString The characters to be searched for at the start of this string.
* @param position The start position at which searchString is expected to be found
* (the index of searchString's first character). Default is `0`
* @returns True if the given characters are found at the beginning of the string,
* including when searchString is an empty string; otherwise, false.
* @param position The start position at which searchString is expected to be found (the index of
* searchString's first character). Default is `0`
* @returns True if the given characters are found at the beginning of the string, including when
* searchString is an empty string; otherwise, false.
*/
export declare function startsWith(string: string, searchString: string, position?: number): boolean;
/**
* Returns a substring by providing start and end position. This function handles Unicode code
* points instead of UTF-16 character codes.
* This function mirrors the `substring` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Returns a substring by providing start and end position.
*
* @param string String to be divided
* @param begin Start position
Expand All @@ -562,8 +601,10 @@ export declare function startsWith(string: string, searchString: string, positio
*/
export declare function substring(string: string, begin: number, end?: number): string;
/**
* Converts a string to an array of string characters. This function handles Unicode code points
* instead of UTF-16 character codes.
* This function mirrors the `toArray` function from the JavaScript Standard String object. It
* handles Unicode code points instead of UTF-16 character codes.
*
* Converts a string to an array of string characters.
*
* @param string String to convert to array
* @returns An array of characters from the starting string
Expand Down Expand Up @@ -1016,8 +1057,4 @@ export declare const menuDocumentSchema: {
};
};

export {
length$1 as length,
};

export {};
4 changes: 2 additions & 2 deletions lib/platform-bible-utils/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/platform-bible-utils/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/platform-bible-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export {
includes,
indexOf,
lastIndexOf,
length,
stringLength,
normalize,
padEnd,
padStart,
Expand Down
8 changes: 4 additions & 4 deletions lib/platform-bible-utils/src/string-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
includes,
indexOf,
lastIndexOf,
length,
stringLength,
normalize,
padEnd,
padStart,
Expand Down Expand Up @@ -47,12 +47,12 @@ describe('at', () => {
});

test('at with index greater than length returns undefined', () => {
const result = at(LONG_SURROGATE_PAIRS_STRING, length(LONG_SURROGATE_PAIRS_STRING) + 10);
const result = at(LONG_SURROGATE_PAIRS_STRING, stringLength(LONG_SURROGATE_PAIRS_STRING) + 10);
expect(result).toEqual(undefined);
});

test('at with index smaller than -length returns undefined', () => {
const result = at(LONG_SURROGATE_PAIRS_STRING, -length(LONG_SURROGATE_PAIRS_STRING) - 10);
const result = at(LONG_SURROGATE_PAIRS_STRING, -stringLength(LONG_SURROGATE_PAIRS_STRING) - 10);
expect(result).toEqual(undefined);
});
});
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('lastIndexOf', () => {

describe('length', () => {
test('length is correct', () => {
const result = length(LONG_SURROGATE_PAIRS_STRING);
const result = stringLength(LONG_SURROGATE_PAIRS_STRING);
expect(result).toEqual(SURROGATE_PAIRS_STRING_LENGTH);
});
});
Expand Down
Loading

0 comments on commit 36479d8

Please sign in to comment.