diff --git a/README.md b/README.md index dfc2a32..6e700b2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/documentation/README.md b/documentation/README.md index 2b69db0..7eecd13 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -14,6 +14,8 @@ - [bitOr](#bitor) - [butLast](#butlast) - [by](#by) +- [charCodeAt](#charcodeat) +- [codePointAt](#codepointat) - [compose](#compose) - [composeAll](#composeall) - [concat](#concat) @@ -282,6 +284,40 @@ by(6, 2); // => 3 +### charCodeAt + +Same as `'STR'.charCodeAt(0)`. + +```js +var charCodeAt = require('1-liners/charCodeAt'); + +charCodeAt(0, 'super') // => 115 +``` + +
+ Spec + • + Source: (index, str) => str.charCodeAt(index); +
+ + +### codePointAt + +Same as `'STR'.codePointAt(0)`. + +```js +var codePointAt = require('1-liners/codePointAt'); + +codePointAt(0, 'super') // => 115 +``` + +
+ Spec + • + Source: (index, str) => str.codePointAt(index); +
+ + ### compose Compose a new function from two given functions. diff --git a/module/charCodeAt.js b/module/charCodeAt.js new file mode 100644 index 0000000..c5507e2 --- /dev/null +++ b/module/charCodeAt.js @@ -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); \ No newline at end of file diff --git a/module/codePointAt.js b/module/codePointAt.js new file mode 100644 index 0000000..b8f05d6 --- /dev/null +++ b/module/codePointAt.js @@ -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); \ No newline at end of file diff --git a/module/index.js b/module/index.js index 5c7f471..135d394 100644 --- a/module/index.js +++ b/module/index.js @@ -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'; @@ -114,6 +116,8 @@ export { bitOr, butLast, by, + charCodeAt, + codePointAt, compose, composeAll, concat, diff --git a/tests/charCodeAt.js b/tests/charCodeAt.js new file mode 100644 index 0000000..b023acd --- /dev/null +++ b/tests/charCodeAt.js @@ -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); +}); diff --git a/tests/codePointAt.js b/tests/codePointAt.js new file mode 100644 index 0000000..c8a2adb --- /dev/null +++ b/tests/codePointAt.js @@ -0,0 +1,7 @@ +import { equal } from 'assert'; +import codePointAt from '../codePointAt'; + +test('#codePointAt', () => { + equal(codePointAt(1, 'ᴅᴇᴄᴇᴘᴛɪᴠᴇ ᴜɴɪᴄᴏᴅᴇ'), 7431); + equal(codePointAt(0, '😀'), 128512); +});