Skip to content

Commit

Permalink
Add explanation for the { position, codePoint } design
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
RReverser committed May 19, 2018
1 parent f8ec08b commit 50c13a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ function* tokenise(input) {
}
```

## FAQ

1. Why does iterator emit an object instead of an array like other key-value iterators?

`[key, value]` format is usually used for entries of collections which can be directly indexed by `key`.

Unlike those collections, strings in ECMAScript are indexed [as 16-bit units of UTF-16 text](https://tc39.github.io/ecma262/#sec-terms-and-definitions-string-value) and not code points, so emitted objects won't have consequent indices but rather positions which might be 1 or 2 16-bit units away from each other.

To make the fact that they represent different measurement units and string representations explicit, we decided on `{ position, codePoint }` object format.

See [#1](https://github.com/tc39/proposal-string-prototype-codepoints/issues/1) for more details.

## Specification

You can view the rendered spec [here](https://tc39.github.io/proposal-string-prototype-codepoints/).
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@
text-align: right;
padding-right: 5px;
}
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#sec-properties-of-the-string-prototype-object" title="Properties of the String Prototype Object"><span class="secnum">1</span> Properties of the String Prototype Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-@@iterator" title="String.prototype [ @@iterator ] ( )"><span class="secnum">1.1</span> String.prototype [ @@iterator ] ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-codepoints" title="String.prototype.codePoints ( )"><span class="secnum">1.2</span> String.prototype.codePoints ( )</a></li></ol></li><li><span class="item-toggle">◢</span><a href="#sec-string-iterator-objects" title="String Iterator Objects"><span class="secnum">2</span> String Iterator Objects</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-createstringiterator" title="CreateStringIterator ( string, kind )"><span class="secnum">2.1</span> CreateStringIterator ( <var>string</var>, <ins><var>kind</var></ins> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-%stringiteratorprototype%-object" title="The %StringIteratorPrototype% Object"><span class="secnum">2.2</span> The %StringIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-%stringiteratorprototype%.next" title="%StringIteratorPrototype%.next ( )"><span class="secnum">2.2.1</span> %StringIteratorPrototype%.next ( )</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-string-iterator-instances" title="Properties of String Iterator Instances"><span class="secnum">2.3</span> Properties of String Iterator Instances</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage 1 Draft / May 8, 2018</h1><h1 class="title">String.prototype.codePoints</h1>
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle">◢</span><a href="#sec-properties-of-the-string-prototype-object" title="Properties of the String Prototype Object"><span class="secnum">1</span> Properties of the String Prototype Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-@@iterator" title="String.prototype [ @@iterator ] ( )"><span class="secnum">1.1</span> String.prototype [ @@iterator ] ( )</a></li><li><span class="item-toggle-none"></span><a href="#sec-string.prototype-codepoints" title="String.prototype.codePoints ( )"><span class="secnum">1.2</span> String.prototype.codePoints ( )</a></li></ol></li><li><span class="item-toggle">◢</span><a href="#sec-string-iterator-objects" title="String Iterator Objects"><span class="secnum">2</span> String Iterator Objects</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-createstringiterator" title="CreateStringIterator ( string, kind )"><span class="secnum">2.1</span> CreateStringIterator ( <var>string</var>, <ins><var>kind</var></ins> )</a></li><li><span class="item-toggle">◢</span><a href="#sec-%stringiteratorprototype%-object" title="The %StringIteratorPrototype% Object"><span class="secnum">2.2</span> The %StringIteratorPrototype% Object</a><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-%stringiteratorprototype%.next" title="%StringIteratorPrototype%.next ( )"><span class="secnum">2.2.1</span> %StringIteratorPrototype%.next ( )</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-properties-of-string-iterator-instances" title="Properties of String Iterator Instances"><span class="secnum">2.3</span> Properties of String Iterator Instances</a></li></ol></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage 1 Draft / May 19, 2018</h1><h1 class="title">String.prototype.codePoints</h1>
<!-- es6num="21.1.3" -->
<emu-clause id="sec-properties-of-the-string-prototype-object">
Expand Down

0 comments on commit 50c13a9

Please sign in to comment.