Skip to content

Commit

Permalink
deprecate obj_values(), obj_entries() and other ES6 shims
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Nov 11, 2024
1 parent fbe13e7 commit 23c06da
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Twinkle core",
"name": "twinkle-core",
"version": "3.1.3",
"version": "3.1.4",
"repository": {
"type": "git",
"url": "https://github.com/wikimedia-gadgets/twinkle-core"
Expand Down
8 changes: 4 additions & 4 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export class Config {
container.style.width = '100%';
contentform.appendChild(container);

obj_values(Config.sections).forEach((section) => {
Object.values(Config.sections).forEach((section) => {
if (section.hidden || (section.adminOnly && !Morebits.userIsSysop)) {
return true; // i.e. "continue" in this context
}
Expand Down Expand Up @@ -746,7 +746,7 @@ export class Config {
var wantedpref = e.target.id.substring(21); // "twinkle-config-reset-" prefix is stripped

// search tactics
obj_values(Config.sections).forEach(function (section) {
Object.values(Config.sections).forEach(function (section) {
if (section.hidden || (section.adminOnly && !Morebits.userIsSysop)) {
return true; // continuze: skip impossibilities
}
Expand Down Expand Up @@ -802,7 +802,7 @@ export class Config {

static resetAllPrefs() {
// no confirmation message - the user can just refresh/close the page to abort
obj_values(Config.sections).forEach(function (section: PreferenceGroup) {
Object.values(Config.sections).forEach(function (section: PreferenceGroup) {
if (section.hidden || (section.adminOnly && !Morebits.userIsSysop)) {
return true; // continue: skip impossibilities
}
Expand Down Expand Up @@ -866,7 +866,7 @@ export class Config {
return a === b;
};

obj_values(Config.sections).forEach(function (section: PreferenceGroup) {
Object.values(Config.sections).forEach(function (section: PreferenceGroup) {
if (section.adminOnly && !Morebits.userIsSysop) {
return; // i.e. "continue" in this context
}
Expand Down
2 changes: 1 addition & 1 deletion src/messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function initMessaging() {
banana = new Banana(Twinkle.language);

// Register plugins
obj_entries(i18nParserPlugins).forEach(([name, plugin]) => {
Object.entries(i18nParserPlugins).forEach(([name, plugin]) => {
banana.registerParserPlugin(name, plugin);
});

Expand Down
4 changes: 2 additions & 2 deletions src/modules/tagCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ export abstract class TagMode {
this.flatObject[item.tag] = item;
});
} else {
obj_values(this.tagList).forEach((group: tagData[] | Record<string, tagData[]>) => {
Object.values(this.tagList).forEach((group: tagData[] | Record<string, tagData[]>) => {
// what's wrong with this type?
obj_values(group).forEach((subgroup: tagData | tagData[]) => {
Object.values(group).forEach((subgroup: tagData | tagData[]) => {
if (Array.isArray(subgroup)) {
subgroup.forEach((item) => {
this.flatObject[item.tag] = item;
Expand Down
10 changes: 8 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export function makeTemplate(name: string, parameters: Record<string | number, s
/**
* Shim for Object.values
* @param obj
* @deprecated as ES6 is now supported in most browsers
*/
export function obj_values<T>(obj: { [s: string]: T } | ArrayLike<T>): T[] {
// @ts-ignore
Expand All @@ -157,6 +158,7 @@ export function obj_values<T>(obj: { [s: string]: T } | ArrayLike<T>): T[] {
/**
* Shim for Object.entries
* @param obj
* @deprecated as ES6 is now supported in most browsers
*/
export function obj_entries<T>(obj: { [s: string]: T } | ArrayLike<T>): [string, T][] {
// @ts-ignore
Expand All @@ -166,6 +168,7 @@ export function obj_entries<T>(obj: { [s: string]: T } | ArrayLike<T>): [string,
/**
* Shim for Object.fromEntries
* @param entries
* @deprecated as ES6 is now supported in most browsers
*/
export function obj_fromEntries<T>(entries: [string, T][]): Record<string, T> {
// @ts-ignore
Expand All @@ -184,7 +187,7 @@ export function obj_fromEntries<T>(entries: [string, T][]): Record<string, T> {
* Shim for Array.prototype.includes
* @param arr
* @param item
* @deprecated as this is now shimmed in MediaWiki
* @deprecated as ES6 is now supported in most browsers
*/
export function arr_includes<T>(arr: Array<T>, item: T): boolean {
return arr.indexOf(item) !== -1;
Expand All @@ -194,7 +197,7 @@ export function arr_includes<T>(arr: Array<T>, item: T): boolean {
* Shim for Array.prototype.find
* @param arr
* @param predicate
* @deprecated as this is now shimmed in MediaWiki
* @deprecated as ES6 is now supported in most browsers
*/
export function arr_find<T>(arr: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean) {
return Array.prototype.find ? arr.find(predicate) : arr.filter(predicate)[0];
Expand All @@ -221,6 +224,7 @@ export function arr_flatMap<T>(
* Shim for String.prototype.includes
* @param str
* @param item
* @deprecated as ES6 is now supported in most browsers
*/
export function str_includes(str: string, item: string): boolean {
return str.indexOf(item) !== -1;
Expand All @@ -230,6 +234,7 @@ export function str_includes(str: string, item: string): boolean {
* Shim for String.prototype.startsWith
* @param str
* @param text
* @deprecated as ES6 is now supported in most browsers
*/
export function str_startsWith(str: string, text: string): boolean {
// @ts-ignore
Expand All @@ -240,6 +245,7 @@ export function str_startsWith(str: string, text: string): boolean {
* Shim for String.prototype.endsWith
* @param str
* @param text
* @deprecated as ES6 is now supported in most browsers
*/
export function str_endsWith(str: string, text: string): boolean {
// @ts-ignore
Expand Down
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "ES2020",
"lib": [
"dom",
"es5",
"es2015.collection"
// Only Map and Set from this are supported in IE 11.
"es6",
],
"outDir": "./js",
"sourceMap": true,
Expand Down

0 comments on commit 23c06da

Please sign in to comment.