-
Notifications
You must be signed in to change notification settings - Fork 0
common.ts
-
getInputData() ⇒
Object
Returns an object containing references to input elements on the page.
-
versionDropdown() ⇒
void
Creates a version dropdown menu in the app UI with custom text labels for certain options.
-
setDropdownOptions(element, values, [texts]) ⇒
undefined
Sets the options in a dropdown element based on an array of values and corresponding text.
-
autoShow() ⇒
void
Automatically sets up input fields, checkboxes, stores, and datalists with appropriate functions.
-
showAll() ⇒
void
Displays all input fields, checkboxes, dropdowns, and other relevant elements to the webpage.
- wikiCode(element, dest)
Updates a destination element with the sanitized value of a source element's value or content.
- checkboxWikiCode(element)
Handles the change event for a checkbox and updates a DOM element's text and page data accordingly.
- storeData(element, [key])
Stores the value of a DOM element in the page data object.
-
externalLinks() ⇒
void
Adds target and rel attributes to all external links on the page.
-
openWikiLinksExternally() ⇒
void
Update all wiki links on the page to open in a new tab.
- wikiCodeSimple(element)
Places a value from an element into an output element. Does not sanitize wikitext. Can also handle one-to-many relationships.
- addStaticPageData(key, value)
Adds static page data to the pageData object. This data is read-only and cannot be changed or deleted.
-
sanitiseString(input) ⇒
string
Sanitizes a given string by removing all non-link wiki markup, and trimming the result.
-
image(element) ⇒
void
Handles a file input change event, sanitizes the filename, and generates wiki code. Throws an error if the file size is larger than 10MB.
- toggleSection(sectionName, button, [attributeName])
Toggles the visibility of all elements with a matching
data-${attributeName}
attribute based on the givensectionName
. If called without arguments, initializes button elementdata-display${id}
attributes for all buttons with class 'sectionToggle'.-
researchTeamDropdown([inputElement]) ⇒
void
Generates a dropdown for selecting a research team.
-
researchTeam() ⇒
void
-
Adds a "researchteam" value to
pageData
, and displays it on the page.If no "researchteam" value is given, this function will add a default value based on the "civilized" value in
pageData
.Additionally, this function expands some "civilized" specific "researchteam" values, and updates the displayed value on the page.
-
docBy() ⇒
void
Adds documentation to a page if the documenter is not the same as the discoverer. If docByExternal is defined, it will call that function instead.
-
displayResearch() ⇒
string
Adjusts the researchteam for display in a sentence.
-
formatName(documenter) ⇒
string
Formats a name to conform to wiki standards. Plain name is italicised, while a linked name has no formatting.
-
hideDiscoverer([keepId], [removeId]) ⇒
undefined
Hides the discoverer input fields for a set of paired inputs if one input is populated. If no input IDs are specified, shows all input fields.
-
addInfoBullet() ⇒
void
Enables bulletpoint content if more than one sentence.
-
errorMessage(element, [msg]) ⇒
void
Displays an error message for a given input element in a table cell.
-
validateCoords([error]) ⇒
string
Validates input coordinates in the format "+/-ddd.dd, +/-ddd.dd". Throws an error message if the input is invalid.
-
hideInput(element, [displayValue]) ⇒
void
Hides an input cell and its label cell.
-
enPrefix(text, [dest]) ⇒
string
Returns the English article "a" or "an" which should be used before a given word.
-
regexMatch(string, regex) ⇒
boolean
Returns true if a string matches a given regular expression.
-
docByResearchteam() ⇒
string
Returns documentation text for a discovery page based on the research team that documented it.
-
numberStats(element, [decimals], [outputRaw]) ⇒
string
|Object
This function calculates the sum, average, minimum, and maximum of a set of numbers, and formats the results for display on a web page. If no arguments are provided, the function will automatically find and calculate the numbers for all elements with the
numberStats
property.-
numberError(element, [value], [decimals], [outputRaw]) ⇒
string
|number
Validates that a given input element contains only numeric characters, and displays an error message if it doesn't.
-
getNumber(number, [decimals], [outputRaw]) ⇒
string
|number
Parses a string containing a number and returns it as a formatted number string or numeric value.
- datalists(object)
-
Creates HTML5 datalists with the provided entries and appends them to the
tag. -
forceDatalist(element) ⇒
void
Validates the option selected in a datalist element.
-
checkDataIntegrity([element], [simple]) ⇒
string
Checks the integrity of the page data and returns an error message if there's an issue.
-
removeNewlines(text) ⇒
string
Removes all newlines from a given string.
-
getSelectedText(section) ⇒
void
Returns the selected text within a given section of the wiki page, after performing some preprocessing to remove unwanted text.
-
enableTextMarking() ⇒
void
Enables text marking on the page. If in debug mode, marks all text. Otherwise, marks only text that has errors.
-
preventCopy() ⇒
void
Checks data integrity and displays an error message if data is missing or incorrect
-
assignDefaultValue(element, [value]) ⇒
void
Assigns a default value to an element if it is empty
-
removeSection(array) ⇒
void
Removes all sections in a given array
-
removeSpecificSection(sectionName, [attribute]) ⇒
void
Removes a specific section based on its name and an attribute
-
hideOrgName() ⇒
void
Hides the original name in wikicode if not provided
-
getChildIndex(array, data) ⇒
number
Returns the next available child index of an array of objects, based on a given property.
-
sortObj(obj, [number]) ⇒
Object
Sorts an object alphabetically by keys.
-
extractNumber(string) ⇒
string
Returns a number containing all the integers in a given string. This function only works for integers. If there are no integers, returns an empty string.
-
oddEven(number) ⇒
string
Returns a string indicating whether a given number is even or odd.
-
loadHTML(html, [varObj], [funcArray]) ⇒
string
|Document
Replace specified variables in a HTML string, and add eventListeners to the resulting DOM.
Returns an object containing references to input elements on the page.
Kind: global function
Returns: Object
-
An object with properties "inputs", "checkboxes", "stores", "defaults", "simple", and "lists", each containing an array of relevant input elements.
Creates a version dropdown menu in the app UI with custom text labels for certain options.
Sets the options in a dropdown element based on an array of values and corresponding text.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
element | HTMLElement |
The dropdown element to update. |
|
values | Array |
An array of values to use for each option. |
|
[texts] | Array |
values |
An optional array of text to use for each option. If no text is provided, the value will be used instead. |
Automatically sets up input fields, checkboxes, stores, and datalists with appropriate functions.
Kind: global function
Returns: void
-
Nothing is returned by this function.
Displays all input fields, checkboxes, dropdowns, and other relevant elements to the webpage.
Updates a destination element with the sanitized value of a source element's value or content.
Kind: global function
Param | Type | Description |
---|---|---|
element | Object |
The source element to retrieve value or content from. |
dest | string |
The ID of the destination element(s) to update, specified in a data attribute on the source element. |
Handles the change event for a checkbox and updates a DOM element's text and page data accordingly.
Kind: global function
Param | Type | Description |
---|---|---|
element | Object |
The checkbox element that triggered the event. |
Stores the value of a DOM element in the page data object.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
element | Object |
The DOM element whose value will be stored. |
|
[key] | string |
"element.dataset.destNoauto" |
The key under which the value will be stored in the page data object. Defaults to the value of the element's |
Adds target and rel attributes to all external links on the page.
Update all wiki links on the page to open in a new tab.
Places a value from an element into an output element. Does not sanitize wikitext. Can also handle one-to-many relationships.
Kind: global function
Param | Type | Description |
---|---|---|
element | HTMLElement |
The input element to source the value from. |
Adds static page data to the pageData object. This data is read-only and cannot be changed or deleted.
Kind: global function
Param | Type | Description |
---|---|---|
key | string |
The key of the data to add. |
value | * |
The value of the data to add. |
Sanitizes a given string by removing all non-link wiki markup, and trimming the result.
Kind: global function
Returns: string
-
The sanitized string with all non-link wiki markup removed.
Param | Type | Description |
---|---|---|
input | string |
The string to sanitize. Must contain only wiki links, templates, and external links in wiki markup. |
Example
// returns "this [[is]] a test [[with some extra markup mixed in]]crazy[http://test-link.com]link[http://another-link.net]abc[[d]]efghijklmnopqrstuv^w_x[[yz[http://nested-link.com]"
const inputString = "this [[is]] a {test} [[with] some {extra} {markup} {mixed [in}]}]crazy[http://test-link.com]link[http://another-link.net][a][b][c][[d]]e{f}g{hi}jkl[m]nop[qrs]t[u]v^w_x[[y]z{[http://nested-link.com]}";
const outputString = sanitiseString(inputString);
-
sanitiseString(input) ⇒
string
-
~removeSpecificMarkup(string, markup) ⇒
string
-
~skipFirst(string, char) ⇒
string
-
~removeSpecificMarkup(string, markup) ⇒
Removes all instances of a specific wiki markup character from a given string.
Kind: inner method of sanitiseString
Returns: string
-
The string with all instances of the markup character removed.
Param | Type | Description |
---|---|---|
string | string |
The string to remove markup from. |
markup | string |
The wiki markup character to remove. |
Removes the first occurrence of a given character in every occurrence of a double-wiki-markup-separated string.
Kind: inner method of sanitiseString
Returns: string
-
The modified string with the character removed.
Param | Type | Description |
---|---|---|
string | string |
The string to modify. |
char | string |
The character to remove. |
Handles a file input change event, sanitizes the filename, and generates wiki code. Throws an error if the file size is larger than 10MB.
Kind: global function
Param | Type | Description |
---|---|---|
element | HTMLInputElement |
The file input element to process. |
Toggles the visibility of all elements with a matching data-${attributeName}
attribute
based on the given sectionName
. If called without arguments, initializes button element data-display${id}
attributes for all buttons with class 'sectionToggle'.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
sectionName | string |
The value of the |
|
button | HTMLElement |
The button element that triggered the toggle action. |
|
[attributeName] | string |
"'section'" |
The name of the data attribute to match against. |
Generates a dropdown for selecting a research team.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
[inputElement] | HTMLInputElement |
globalElements.input.researchTeam |
The input element to generate the dropdown for. |
Adds a "researchteam" value to pageData
, and displays it on the page.
If no "researchteam" value is given, this function will add a default value based on the "civilized" value in pageData
.
Additionally, this function expands some "civilized" specific "researchteam" values, and updates the displayed value on the page.
Adds documentation to a page if the documenter is not the same as the discoverer. If docByExternal is defined, it will call that function instead.
Adjusts the researchteam for display in a sentence.
Kind: global function
Returns: string
-
Returns a string that describes the research team
Formats a name to conform to wiki standards. Plain name is italicised, while a linked name has no formatting.
Kind: global function
Returns: string
-
- The formatted name.
Param | Type | Description |
---|---|---|
documenter | string |
The name to be formatted. |
Hides the discoverer input fields for a set of paired inputs if one input is populated. If no input IDs are specified, shows all input fields.
Kind: global function
Param | Type | Description |
---|---|---|
[keepId] | string |
ID of paired input to keep visible. |
[removeId] | string |
ID of paired input to hide. |
Enables bulletpoint content if more than one sentence.
Displays an error message for a given input element in a table cell.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
element | HTMLElement |
The input element for which to display the error. |
|
[msg] |
string | null
|
null |
The error message to display. If null, any existing error message is removed. |
Validates input coordinates in the format "+/-ddd.dd, +/-ddd.dd". Throws an error message if the input is invalid.
Kind: global function
Returns: string
-
- Returns "error" if the input is invalid, otherwise returns undefined.
Param | Type | Default | Description |
---|---|---|---|
[error] | Boolean |
true |
Whether to display an error message if the input is invalid. Defaults to true. |
Example
// The following input would be considered invalid: "12.34, 56.78"
validateCoords();
Hides an input cell and its label cell.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
element | HTMLElement |
The input element to be hidden. |
|
[displayValue] | string |
null |
The CSS display value to apply to the input and label cells. Defaults to an empty string if not specified. |
Returns the English article "a" or "an" which should be used before a given word.
Kind: global function
Returns: string
-
The article to use before text
.
Param | Type | Default | Description |
---|---|---|---|
text | string |
The word to prefix with an article. |
|
[dest] | string |
null |
The destination to write the output to using |
Returns true if a string matches a given regular expression.
Kind: global function
Returns: boolean
-
- True if the string matches the regex, false otherwise.
Param | Type | Description |
---|---|---|
string | string |
The string to match. |
regex | RegExp |
The regular expression to match against. |
Returns documentation text for a discovery page based on the research team that documented it.
Kind: global function
Returns: string
-
- The documentation text, including the research team name if it matches the expected abbreviation.
This function calculates the sum, average, minimum, and maximum of a set of numbers, and formats the results for display on a web page. If no arguments are provided, the function will automatically find and calculate the numbers for all elements with the numberStats
property.
Kind: global function
Returns: string
| Object
-
The formatted statistics string (and optionally, the raw calculation values).
Param | Type | Default | Description |
---|---|---|---|
element | HTMLElement |
|
The HTML element to calculate statistics for. |
[decimals] | number |
|
The number of decimal places to use in formatted results. If |
[outputRaw] | boolean |
false |
Whether to output the raw calculation values along with the formatted results. If |
Validates that a given input element contains only numeric characters, and displays an error message if it doesn't.
Kind: global function
Returns: string
| number
-
- The input value, parsed as a number (if valid) or an empty string (if not valid).
Param | Type | Default | Description |
---|---|---|---|
element | Element |
The input element to validate. |
|
[value] | string |
"element.value" |
The value to validate (defaults to the value of the input element). |
[decimals] | number |
|
The number of decimal places to use when formatting the input value (if outputRaw is false). |
[outputRaw] | boolean |
false |
If true, returns the raw input value without formatting. |
Parses a string containing a number and returns it as a formatted number string or numeric value.
Kind: global function
Returns: string
| number
-
- The parsed number, formatted with commas and the specified number of decimal places (if decimals is non-null), or the raw parsed value (if outputRaw is true).
Param | Type | Default | Description |
---|---|---|---|
number | string |
The string to parse as a number. |
|
[decimals] | number |
|
The number of decimal places to use when formatting the output value. |
[outputRaw] | boolean |
false |
If true, returns the raw parsed value without formatting. |
Creates HTML5 datalists with the provided entries and appends them to the
tag.Kind: global function
Param | Type | Description |
---|---|---|
object | Object |
An object containing datalist IDs as keys with an array of entries as values. |
Example
// Creates a datalist with ID datalist1 and two entries, "entry1" and "entry2"
datalists({datalist1: ["entry1", "entry2"]});
Validates the option selected in a datalist element.
Kind: global function
Param | Type | Description |
---|---|---|
element | HTMLInputElement |
The input element with the datalist. |
Checks the integrity of the page data and returns an error message if there's an issue.
Kind: global function
Returns: string
-
A string with an error message if a data integrity issue was found, or an empty string otherwise.
Param | Type | Default | Description |
---|---|---|---|
[element] | HTMLElement |
|
The HTML element related to the data check. |
[simple] | boolean |
false |
Indicates whether to perform a simple data check. |
Removes all newlines from a given string.
Kind: global function
Returns: string
-
- A modified string with all newlines replaced by empty spaces.
Param | Type | Description |
---|---|---|
text | string |
The text string to remove newlines from. |
Returns the selected text within a given section of the wiki page, after performing some preprocessing to remove unwanted text.
Kind: global function
Param | Type | Description |
---|---|---|
section | HTMLElement |
The HTML element representing the section to search for selected text. |
Enables text marking on the page. If in debug mode, marks all text. Otherwise, marks only text that has errors.
Checks data integrity and displays an error message if data is missing or incorrect
Assigns a default value to an element if it is empty
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
element | HTMLElement |
The element to assign a default value to |
|
[value] | string |
"element.dataset.default" |
The default value to assign (if no value is provided, the element's "data-default" attribute will be used) |
Removes all sections in a given array
Kind: global function
Param | Type | Description |
---|---|---|
array | Array.<HTMLElement> |
The array of elements to remove |
Removes a specific section based on its name and an attribute
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
sectionName | string |
The name of the section to remove |
|
[attribute] | string |
"'section'" |
The data-attribute to search for (defaults to "section") |
Hides the original name in wikicode if not provided
Returns the next available child index of an array of objects, based on a given property.
Kind: global function
Returns: number
-
- The next available child index.
Param | Type | Description |
---|---|---|
array | Array |
The array of objects to check. |
data | string |
The path to the property to check for an index, in dot notation (e.g. 'dataset.planet'). |
Sorts an object alphabetically by keys.
Kind: global function
Returns: Object
-
- A new object with the same key-value pairs as the input object, but with the keys sorted alphabetically.
Param | Type | Default | Description |
---|---|---|---|
obj | Object |
The object to be sorted. |
|
[number] | boolean |
false |
A flag indicating whether numbers should be sorted correctly (i.e. by numerical value) or not (i.e. by string value). Default is false. |
Returns a number containing all the integers in a given string. This function only works for integers. If there are no integers, returns an empty string.
Kind: global function
Returns: string
-
A number containing all the integers in the input string. Returns an empty string if no integers were found.
Param | Type | Description |
---|---|---|
string | string |
The string to extract integers from. |
Returns a string indicating whether a given number is even or odd.
Kind: global function
Returns: string
-
A string indicating whether the number is 'even' or 'odd'
Param | Type | Description |
---|---|---|
number | number |
The number to check. |
Replace specified variables in a HTML string, and add eventListeners to the resulting DOM.
Kind: global function
Returns: string
| Document
-
- A string of the edited HTML or a dom with attached eventListeners, depending on the input arguments.
Param | Type | Description |
---|---|---|
html | string |
The string of HTML to be edited. |
[varObj] | Object |
An object containing key-value pairs to replace in the loaded HTML. |
[funcArray] | Object |
An ElementFunctions array containing event listeners to put in the loaded HTML. |
¡Gracias por utilizar el Creador de páginas para la Wiki! Espero que te ayude a crear páginas increíbles para tus descubrimientos en No Man's Sky. Si tiene algún problema o sugerencia sobre cómo se puede mejorar el proyecto, haganoslo saber.