Update Docs Site (#44)
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { DEV } from 'esm-env';
|
||||
|
||||
/**
|
||||
* Object containing logger functions.
|
||||
* @typedef {Object} Announce
|
||||
* @property {function} info - Log info like events and data.
|
||||
* @property {function} warn - Log warnings for developers.
|
||||
* @property {function} error - Log errors for critical failures.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Type of logger.
|
||||
* @typedef {('info' | 'error' | 'warn')} Logger
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object containing Logger functions.
|
||||
*
|
||||
* @type {Readonly<{[K in Logger]: Function}>}
|
||||
*/
|
||||
const use_logger = Object.freeze({
|
||||
info: console.info,
|
||||
error: console.error,
|
||||
warn: console.warn,
|
||||
});
|
||||
|
||||
/**
|
||||
* Log function.
|
||||
* @param {Logger} type - Type of logger.
|
||||
* @param {...unknown} content - Content to log.
|
||||
*/
|
||||
function log(type, ...content) {
|
||||
const logger = use_logger[type];
|
||||
|
||||
// If type is info and not in dev mode, return early
|
||||
if (type === 'info' && !DEV) return;
|
||||
|
||||
// Log message
|
||||
logger(
|
||||
'%c🔊 svelte-podcast:',
|
||||
'color: #FF3E00; background-color: rgba(255, 62, 0, 0.15); padding: 4px 8px; border-radius:4px;',
|
||||
...content,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Object containing logger functions.
|
||||
* @type {Announce}
|
||||
* @exports announce
|
||||
*/
|
||||
export const announce = {
|
||||
/**
|
||||
* Log an info message.
|
||||
* @param {...unknown} content - Content to log.
|
||||
*/
|
||||
info: (...content) => log('info', ...content),
|
||||
/**
|
||||
* Log a warning message.
|
||||
* @param {...unknown} content - Content to log.
|
||||
*/
|
||||
warn: (...content) => log('warn', ...content),
|
||||
/**
|
||||
* Log an error message.
|
||||
* @param {...unknown} content - Content to log.
|
||||
*/
|
||||
error: (...content) => log('error', ...content),
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Utility functions module.
|
||||
* @module internal
|
||||
*/
|
||||
|
||||
export * from './announce';
|
||||
export * from './use-url';
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @typedef {Object} RelativeURL
|
||||
* @property {string} pathname - The pathname of the URL.
|
||||
* @property {string} search - The search string of the URL.
|
||||
* @property {string} hash - The hash string of the URL.
|
||||
* @property {URLSearchParams} searchParams - The search parameters of the URL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a string to a URL object. If the string is not a valid URL, it will be appended to the Svelte website URL.
|
||||
* @param {string} href - The string to convert to a URL object.
|
||||
* @returns {URL} A URL object.
|
||||
*/
|
||||
const string_to_url = (href) => {
|
||||
try {
|
||||
return new URL(href);
|
||||
} catch (e) {
|
||||
return new URL(href, 'https://svelte.dev');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a URL string and returns an object containing its pathname, search, hash, and searchParams.
|
||||
* @param {string} href - The URL string to parse.
|
||||
* @returns {RelativeURL} An object containing the pathname, search, hash, and searchParams of the URL.
|
||||
*/
|
||||
export const use_url = (href) => {
|
||||
const { pathname, search, hash, searchParams } = string_to_url(href);
|
||||
|
||||
return { pathname, search, hash, searchParams };
|
||||
};
|
||||
Reference in New Issue
Block a user