-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web extension support for daily note (#1426)
* Using nodemon for watch task * Added documentation and generator pattern to support getting some data from multiple sources * asAbsoluteUrl can now take URI or string * Tweaked daily note computation * Replacing URI.withFragment with generic URI.with * Removed URI.file from non-testing code * fixed asAbsoluteUri * Various tweaks and fixes * Fixed create-note command
- Loading branch information
1 parent
1a99e69
commit 6b02a87
Showing
20 changed files
with
330 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,85 @@ | ||
import sha1 from 'js-sha1'; | ||
|
||
/** | ||
* Checks if a value is not null. | ||
* | ||
* @param value - The value to check. | ||
* @returns True if the value is not null, otherwise false. | ||
*/ | ||
export function isNotNull<T>(value: T | null): value is T { | ||
return value != null; | ||
} | ||
|
||
/** | ||
* Checks if a value is not null, undefined, or void. | ||
* | ||
* @param value - The value to check. | ||
* @returns True if the value is not null, undefined, or void, otherwise false. | ||
*/ | ||
export function isSome<T>( | ||
value: T | null | undefined | void | ||
): value is NonNullable<T> { | ||
return value != null; | ||
} | ||
|
||
/** | ||
* Checks if a value is null, undefined, or void. | ||
* | ||
* @param value - The value to check. | ||
* @returns True if the value is null, undefined, or void, otherwise false. | ||
*/ | ||
export function isNone<T>( | ||
value: T | null | undefined | void | ||
): value is null | undefined | void { | ||
return value == null; | ||
} | ||
|
||
/** | ||
* Checks if a string is numeric. | ||
* | ||
* @param value - The string to check. | ||
* @returns True if the string is numeric, otherwise false. | ||
*/ | ||
export function isNumeric(value: string): boolean { | ||
return /-?\d+$/.test(value); | ||
} | ||
|
||
/** | ||
* Generates a SHA-1 hash of the given text. | ||
* | ||
* @param text - The text to hash. | ||
* @returns The SHA-1 hash of the text. | ||
*/ | ||
export const hash = (text: string) => sha1.sha1(text); | ||
|
||
/** | ||
* Executes an array of functions and returns the first result that satisfies the predicate. | ||
* | ||
* @param functions - The array of functions to execute. | ||
* @param predicate - The predicate to test the results. Defaults to checking if the result is not null. | ||
* @returns The first result that satisfies the predicate, or undefined if no result satisfies the predicate. | ||
*/ | ||
export async function firstFrom<T>( | ||
functions: Array<() => T | Promise<T>>, | ||
predicate: (result: T) => boolean = result => result != null | ||
): Promise<T | undefined> { | ||
for (const fn of functions) { | ||
const result = await fn(); | ||
if (predicate(result)) { | ||
return result; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Lazily executes an array of functions and yields their results. | ||
* | ||
* @param functions - The array of functions to execute. | ||
* @returns A generator yielding the results of the functions. | ||
*/ | ||
function* lazyExecutor<T>(functions: Array<() => T>): Generator<T> { | ||
for (const fn of functions) { | ||
yield fn(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.