Skip to content

Commit

Permalink
added charCodeAt() and codePointAt()
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaaan committed Oct 7, 2015
1 parent 4046b85 commit 0d52fc0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@

**Functional tools that couldn’t be simpler.**

<<<<<<< HEAD
We’re proud to present *1-liners* – a dead simple functional utility belt. **[106 one-liner functions][docs]** (and counting). Each hand-crafted with love and attention.
=======
We’re proud to present *1-liners* – a dead simple functional utility belt. **[105 one-liner functions][docs]** (and counting). Each hand-crafted with love and attention.
>>>>>>> added toLowerCase() and toUpperCase()
We’re proud to present *1-liners* – a dead simple functional utility belt. **[108 one-liner functions][docs]** (and counting). Each hand-crafted with love and attention.

[docs]: ./documentation

Expand Down
36 changes: 36 additions & 0 deletions documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- [bitOr](#bitor)
- [butLast](#butlast)
- [by](#by)
- [charCodeAt](#charcodeat)
- [codePointAt](#codepointat)
- [compose](#compose)
- [composeAll](#composeall)
- [concat](#concat)
Expand Down Expand Up @@ -282,6 +284,40 @@ by(6, 2); // => 3
</sup></div>


### charCodeAt

Same as `'STR'.charCodeAt(0)`.

```js
var charCodeAt = require('1-liners/charCodeAt');

charCodeAt(0, 'super') // => 115
```

<div align="right"><sup>
<a href="../tests/charCodeAt.js">Spec</a>
<a href="../module/charCodeAt.js">Source</a>: <code> (index, str) =&gt; str.charCodeAt(index);</code>
</sup></div>


### codePointAt

Same as `'STR'.codePointAt(0)`.

```js
var codePointAt = require('1-liners/codePointAt');

codePointAt(0, 'super') // => 115
```

<div align="right"><sup>
<a href="../tests/codePointAt.js">Spec</a>
<a href="../module/codePointAt.js">Source</a>: <code> (index, str) =&gt; str.codePointAt(index);</code>
</sup></div>


### compose

Compose a new function from two given functions.
Expand Down
15 changes: 15 additions & 0 deletions module/charCodeAt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @module 1-liners/charCodeAt
*
* @description
*
* Same as `'STR'.charCodeAt(0)`.
*
* @example
*
* var charCodeAt = require('1-liners/charCodeAt');
*
* charCodeAt(0, 'super') // => 115
*
*/
export default (index, str) => str.charCodeAt(index);
15 changes: 15 additions & 0 deletions module/codePointAt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @module 1-liners/codePointAt
*
* @description
*
* Same as `'STR'.codePointAt(0)`.
*
* @example
*
* var codePointAt = require('1-liners/codePointAt');
*
* codePointAt(0, 'super') // => 115
*
*/
export default (index, str) => str.codePointAt(index);
4 changes: 4 additions & 0 deletions module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import bitAnd from './bitAnd';
import bitOr from './bitOr';
import butLast from './butLast';
import by from './by';
import charCodeAt from './charCodeAt';
import codePointAt from './codePointAt';
import compose from './compose';
import composeAll from './composeAll';
import concat from './concat';
Expand Down Expand Up @@ -114,6 +116,8 @@ export {
bitOr,
butLast,
by,
charCodeAt,
codePointAt,
compose,
composeAll,
concat,
Expand Down
7 changes: 7 additions & 0 deletions tests/charCodeAt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { equal } from 'assert';
import charCodeAt from '../charCodeAt';

test('#charCodeAt', () => {
equal(charCodeAt(1, 'hallo'), 97);
equal(charCodeAt(3, 'große'), 223);
});
7 changes: 7 additions & 0 deletions tests/codePointAt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { equal } from 'assert';
import codePointAt from '../codePointAt';

test('#codePointAt', () => {
equal(codePointAt(1, 'ᴅᴇᴄᴇᴘᴛɪᴠᴇ ᴜɴɪᴄᴏᴅᴇ'), 7431);
equal(codePointAt(0, '😀'), 128512);
});

0 comments on commit 0d52fc0

Please sign in to comment.