Skip to content

Commit

Permalink
fix: KeyboardLayoutMap.keys/values/entries should have methods type (m…
Browse files Browse the repository at this point in the history
…dn#29957)

* update

* update

* fix readonly

* update summary

* update

* update

* add link

* fix title

* feat: update

* Update files/en-us/web/api/keyboardlayoutmap/entries/index.md

* add content for @@iterator

* update

* fix

* specific spec-urls

* fix word

* add example section

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update files/en-us/web/api/keyboardlayoutmap/has/index.md

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and dipikabh committed Jan 17, 2024
1 parent 58f3093 commit f1aa40d
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 40 deletions.
34 changes: 24 additions & 10 deletions files/en-us/web/api/keyboardlayoutmap/entries/index.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
---
title: "KeyboardLayoutMap: entries property"
short-title: entries
title: "KeyboardLayoutMap: entries() method"
short-title: entries()
slug: Web/API/KeyboardLayoutMap/entries
page-type: web-api-instance-property
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.KeyboardLayoutMap.entries
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.entries
---

{{SeeCompatTable}}{{APIRef("Keyboard API")}}

The **`entries`** read-only property
of the {{domxref("KeyboardLayoutMap")}} interface returns an array of a given object's
own enumerable property `[key, value]` pairs, in the same order as that
provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being
that a for-in loop enumerates properties in the prototype chain as well).
The **`entries()`** method of the {{domxref("KeyboardLayoutMap")}} interface returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the key/value pairs, in the same order as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being that a `for-in` loop enumerates properties in the prototype chain as well).

The method is otherwise the same as {{jsxref("Map.prototype.entries()")}}.

## Value

An array of the given `KeyboardLayoutMap` object's own enumerable property
`[key, value]` pairs.
A new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object.

## Examples

The following example iterates every location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard.

```js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
for (const [code, key] of keyboardLayoutMap.entries()) {
console.log(`${code} keyboard code represents ${key} key`);
}
});
```

## Specifications

Expand All @@ -28,3 +38,7 @@ An array of the given `KeyboardLayoutMap` object's own enumerable property
## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.entries()")}}
19 changes: 19 additions & 0 deletions files/en-us/web/api/keyboardlayoutmap/foreach/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ page-type: web-api-instance-method
status:
- experimental
browser-compat: api.KeyboardLayoutMap.forEach
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.foreach
---

{{APIRef("Keyboard API")}}{{SeeCompatTable}}
Expand All @@ -14,6 +15,8 @@ The **`forEach()`** method of the
{{domxref('KeyboardLayoutMap')}} interface executes a provided function once for
each element of the map.

The method is otherwise the same as {{jsxref("Map.prototype.forEach()")}}.

## Syntax

```js-nolint
Expand Down Expand Up @@ -42,10 +45,26 @@ forEach(callbackFn, thisArg)

None ({{jsxref("undefined")}}).

## Examples

The following example iterates every location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard.

```js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
keyboardLayoutMap.forEach((key, code) => {
console.log(`${code} keyboard code represents ${key} key`);
});
});
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.forEach()")}}
13 changes: 9 additions & 4 deletions files/en-us/web/api/keyboardlayoutmap/get/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ page-type: web-api-instance-method
status:
- experimental
browser-compat: api.KeyboardLayoutMap.get
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.get
---

{{APIRef("Keyboard API")}}{{SeeCompatTable}}
Expand All @@ -16,6 +17,8 @@ key.

A list of valid keys is found in the [UI Events KeyboardEvent code Values](https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system) spec.

The method is otherwise the same as {{jsxref("Map.prototype.get()")}}.

## Syntax

```js-nolint
Expand All @@ -33,12 +36,10 @@ The value of the specified key.

## Examples

The following example demonstrates how to get the location- or layout-specific string
associated with the key that corresponds to the 'W' key on an English QWERTY keyboard.
The following example demonstrates how to get the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard.

```js
const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap) => {
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`Press ${upKey} to move up.`);
});
Expand All @@ -51,3 +52,7 @@ keyboard.getLayoutMap().then((keyboardLayoutMap) => {
## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.get()")}}
17 changes: 17 additions & 0 deletions files/en-us/web/api/keyboardlayoutmap/has/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ page-type: web-api-instance-method
status:
- experimental
browser-compat: api.KeyboardLayoutMap.has
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.has
---

{{APIRef("Keyboard API")}}{{SeeCompatTable}}
Expand All @@ -17,6 +18,8 @@ object has an element with the specified key.
A list of valid keys is found in
the [UI Events KeyboardEvent code Values](https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system) spec.

The method is otherwise the same as {{jsxref("Map.prototype.has()")}}.

## Syntax

```js-nolint
Expand All @@ -32,10 +35,24 @@ has(key)

A {{jsxref('Boolean')}} indicating whether the specified key was found.

## Examples

The following example checks whether the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard existes.

```js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
console.log(keyboardLayoutMap.has("KeyW"));
});
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.has()")}}
21 changes: 11 additions & 10 deletions files/en-us/web/api/keyboardlayoutmap/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,32 @@ A list of valid keys is found in the [UI Events KeyboardEvent code Values](https

## Instance properties

- {{domxref('KeyboardLayoutMap.entries')}} {{ReadOnlyInline}} {{experimental_inline}}
- : Returns an array of a given object's own enumerable property `[key, value]` pairs, in the same order as that provided by a {{jsxref("Statements/for...in", "for...in")}} loop (the difference being that a `for-in` loop enumerates properties in the prototype chain as well).
- {{domxref('KeyboardLayoutMap.keys')}} {{ReadOnlyInline}} {{experimental_inline}}
- : Returns a new _array iterator_ object that contains the keys for each index in the array.
- {{domxref('KeyboardLayoutMap.size')}} {{ReadOnlyInline}} {{experimental_inline}}
- : Returns the number of elements in the `KeyboardLayoutMap` object.
- {{domxref('KeyboardLayoutMap.values')}} {{ReadOnlyInline}} {{experimental_inline}}
- : Returns a new _array iterator_ object that contains the values for each index in the `KeyboardLayoutMap` object.

## Instance methods

- {{domxref('KeyboardLayoutMap.forEach()')}} {{ReadOnlyInline}} {{experimental_inline}}
- `KeyboardLayoutMap.[@@iterator]()` {{experimental_inline}}
- : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the key/value pairs.
- {{domxref('KeyboardLayoutMap.entries()')}} {{experimental_inline}}
- : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the key/value pairs.
- {{domxref('KeyboardLayoutMap.forEach()')}} {{experimental_inline}}
- : Executes a provided function once for each element of `KeyboardLayoutMap`.
- {{domxref('KeyboardLayoutMap.get()')}} {{experimental_inline}}
- : Returns the element with the given key from the `KeyboardLayoutMap` object.
- {{domxref('KeyboardLayoutMap.has()')}} {{experimental_inline}}
- : Returns a boolean indicating whether the `KeyboardLayoutMap` object has an element with the specified key.
- {{domxref('KeyboardLayoutMap.keys()')}} {{experimental_inline}}
- : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the keys for each index in the `KeyboardLayoutMap` object.
- {{domxref('KeyboardLayoutMap.values()')}} {{experimental_inline}}
- : Returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the values for each index in the `KeyboardLayoutMap` object.

## Examples

The following example demonstrates how to get the location- or layout-specific string associated with the key that corresponds to the 'W' key on an English QWERTY keyboard.
The following example demonstrates how to get the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard.

```js
const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap) => {
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`Press ${upKey} to move up.`);
});
Expand Down
32 changes: 24 additions & 8 deletions files/en-us/web/api/keyboardlayoutmap/keys/index.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
---
title: "KeyboardLayoutMap: keys property"
short-title: keys
title: "KeyboardLayoutMap: keys() method"
short-title: keys()
slug: Web/API/KeyboardLayoutMap/keys
page-type: web-api-instance-property
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.KeyboardLayoutMap.keys
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.keys
---

{{SeeCompatTable}}{{APIRef("Keyboard API")}}

The **`keys`** read-only property of
the {{domxref("KeyboardLayoutMap")}} interface returns a new Array
Iterator object that contains the keys for each index in the
array.
The **`keys()`** method of the {{domxref("KeyboardLayoutMap")}} interface returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the keys for each index in the `KeyboardLayoutMap` object.

The method is otherwise the same as {{jsxref("Map.prototype.keys()")}}.

## Value

An iterator.
A new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object.

## Examples

The following example iterates every keyboard code on an English QWERTY keyboard.

```js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
for (const code of keyboardLayoutMap.keys()) {
console.log(`${code} keyboard code`);
}
});
```

## Specifications

Expand All @@ -26,3 +38,7 @@ An iterator.
## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.keys()")}}
17 changes: 17 additions & 0 deletions files/en-us/web/api/keyboardlayoutmap/size/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ page-type: web-api-instance-property
status:
- experimental
browser-compat: api.KeyboardLayoutMap.size
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-get-map.prototype.size
---

{{SeeCompatTable}}{{APIRef("Keyboard API")}}
Expand All @@ -14,14 +15,30 @@ The **`size`** read-only property of
the {{domxref("KeyboardLayoutMap")}} interface returns the number of elements in the
map.

The property is otherwise the same as {{jsxref("Map.prototype.size")}}.

## Value

A number.

## Examples

The following example get the count of the location- or layout-specific string and its associated keyboard code on an English QWERTY keyboard.

```js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
console.log(keyboardLayoutMap.size);
});
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.size")}}
32 changes: 24 additions & 8 deletions files/en-us/web/api/keyboardlayoutmap/values/index.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
---
title: "KeyboardLayoutMap: values property"
short-title: values
title: "KeyboardLayoutMap: values() method"
short-title: values()
slug: Web/API/KeyboardLayoutMap/values
page-type: web-api-instance-property
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.KeyboardLayoutMap.values
spec-urls: https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.prototype.values
---

{{SeeCompatTable}}{{APIRef("Keyboard API")}}

The **`values`** read-only property of
the {{domxref("KeyboardLayoutMap")}} interface returns a new Array
Iterator object that contains the values for each index in the
map.
The **`values()`** method of the {{domxref("KeyboardLayoutMap")}} interface returns a new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object that contains the values for each index in the `KeyboardLayoutMap` object.

The method is otherwise the same as {{jsxref("Map.prototype.values()")}}.

## Value

An iterator.
A new [Iterator](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) object.

## Examples

The following example iterates every location- or layout-specific string on an English QWERTY keyboard.

```js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
for (const key of keyboardLayoutMap.values()) {
console.log(`${key} key`);
}
});
```

## Specifications

Expand All @@ -26,3 +38,7 @@ An iterator.
## Browser compatibility

{{Compat}}

## See also

- {{jsxref("Map.prototype.values()")}}

0 comments on commit f1aa40d

Please sign in to comment.