Skip to content

Commit

Permalink
Merge pull request #4 from cAttte/html-and-log
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp authored Mar 5, 2021
2 parents af2dbac + 77dc36c commit d966500
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 26 deletions.
36 changes: 36 additions & 0 deletions mw/html.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
declare global {
namespace mw {
namespace html {
/**
* Escape a string for HTML.
* Converts special characters to HTML entities.
* @param {string} s The string to escape
* @returns {string} HTML
*/
function escape(s: string): string;

/**
* Create an HTML element string, with safe escaping.
* @param {string} name The tag name
* @param {{ [key: string]: string }} attrs An object with members mapping element names to values
* @param {string | html.Raw} contents The contents of the element
* @returns {string} HTML
*/
function element(
name: string,
attrs?: Record<string, string>,
contents?: string | mw.html.Raw
): string;

/**
* Wrapper object for raw HTML passed to mw.html.element().
*/
class Raw<V extends string = string> {
constructor(value: V);
private value: V;
}
}
}
}

export {};
34 changes: 8 additions & 26 deletions mw/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import "./Api";
import "./hook";
import "./html";
import "./language";
import "./util";
import "./user";
import "./loader";
import "./log";
import "./Map";
import "./message";
import "./notification";
import "./storage";
import "./Title";
import "./Uri";
import "./hook";
import "./storage";
import "./notification";
import "./message";
import "./user";
import "./util";

declare global {
/**
Expand Down Expand Up @@ -85,26 +87,6 @@ declare global {
[key: string]: unknown; // more config keys can be added by extensions
}>;

namespace html {
function escape(s: string): string;

function element(name: string, attrs?: any, contents?: string): string;
}

namespace log {
function deprecate(
obj: any,
key: string,
val: any,
msg?: string,
logName?: string
): void;

function error(...msg: any[]): void;

function warn(...msg: string[]): void;
}

// types for mw.widgets are out of scope!
const widgets: any;
}
Expand Down
44 changes: 44 additions & 0 deletions mw/log.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
declare global {
namespace mw {
namespace log {
/**
* Create a property on a host object that, when accessed, will produce a deprecation warning in the console.
* @param {*} obj Host object of deprecated property
* @param {string} key Name of property to create in `obj`
* @param {*} val The value this property should return when accessed
* @param {string?} msg Optional text to include in the deprecation message
* @param {string?} logName Name for the feature for logging and tracking purposes. Except for properties of the window object, tracking is only enabled if logName is set
* @returns {void}
*/
function deprecate(
obj: any,
key: string,
val: any,
msg?: string,
logName?: string
): void;

/**
* Write a message to the browser console's error channel.
*
* Most browsers also print a stacktrace when calling this method if the argument is an Error object.
*
* This method is a no-op in browsers that don't implement the Console API.
* @param {Array<*>} msg Messages to output to console
* @returns {void}
*/
function error(...msg: any[]): void;

/**
* Write a message to the browser console's warning channel.
*
* This method is a no-op in browsers that don't implement the Console API.
* @param msg Messages to output to console
* @returns {void}
*/
function warn(...msg: any[]): void;
}
}
}

export {};

0 comments on commit d966500

Please sign in to comment.