mirror of
https://github.com/Bismuth-Forge/bismuth.git
synced 2024-09-17 11:37:10 +03:00
docs: add JSDoc to some functions in func.ts
This commit is contained in:
parent
033fb19570
commit
555430dda9
@ -3,6 +3,10 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return `value`, if it is in range of [`min`, `max`]. Otherwise return
|
||||||
|
* the the closest range ends to it.
|
||||||
|
*/
|
||||||
export function clip(value: number, min: number, max: number): number {
|
export function clip(value: number, min: number, max: number): number {
|
||||||
if (value < min) {
|
if (value < min) {
|
||||||
return min;
|
return min;
|
||||||
@ -13,6 +17,9 @@ export function clip(value: number, min: number, max: number): number {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the value gradually, multiplying it by (step / (1 + step))
|
||||||
|
*/
|
||||||
export function slide(value: number, step: number): number {
|
export function slide(value: number, step: number): number {
|
||||||
if (step === 0) {
|
if (step === 0) {
|
||||||
return value;
|
return value;
|
||||||
@ -20,6 +27,12 @@ export function slide(value: number, step: number): number {
|
|||||||
return Math.floor(value / step + 1.000001) * step;
|
return Math.floor(value / step + 1.000001) * step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the words in the string.
|
||||||
|
* @param str the string to search words in
|
||||||
|
* @param words the words to be searched
|
||||||
|
* @returns index of a word, that was found in the string first. -1 if none of the words were found.
|
||||||
|
*/
|
||||||
export function matchWords(str: string, words: string[]): number {
|
export function matchWords(str: string, words: string[]): number {
|
||||||
for (let i = 0; i < words.length; i++) {
|
for (let i = 0; i < words.length; i++) {
|
||||||
if (str.indexOf(words[i]) >= 0) {
|
if (str.indexOf(words[i]) >= 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user