Skip to content

Commit

Permalink
Merge pull request 1-liners#142 from tristaaan/simple-string-functions
Browse files Browse the repository at this point in the history
Simple string functions
  • Loading branch information
stoeffel committed Oct 8, 2015
2 parents e307601 + e8a12cb commit 091e287
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

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

We’re proud to present *1-liners* – a dead simple functional utility belt. **[104 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. **[111 one-liner functions][docs]** (and counting). Each hand-crafted with love and attention.

[docs]: ./documentation

Expand Down
131 changes: 130 additions & 1 deletion 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 @@ -44,6 +46,7 @@
- [ifThenElse](#ifthenelse)
- [implode](#implode)
- [inc](#inc)
- [indexOf](#indexof)
- [isBetween](#isbetween)
- [isBoolean](#isboolean)
- [isFalse](#isfalse)
Expand All @@ -62,6 +65,7 @@
- [join](#join)
- [keys](#keys)
- [last](#last)
- [lastIndexOf](#lastindexof)
- [length](#length)
- [lessOrEqual](#lessorequal)
- [lessThan](#lessthan)
Expand Down Expand Up @@ -93,6 +97,7 @@
- [shallowClone](#shallowclone)
- [shave](#shave)
- [signum](#signum)
- [slice](#slice)
- [some](#some)
- [split](#split)
- [startsWith](#startswith)
Expand All @@ -104,6 +109,8 @@
- [takeWhile](#takewhile)
- [test](#test)
- [times](#times)
- [toLowerCase](#tolowercase)
- [toUpperCase](#touppercase)
- [uncurry](#uncurry)
- [uncurry3](#uncurry3)
- [values](#values)
Expand Down Expand Up @@ -280,6 +287,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 Expand Up @@ -429,7 +470,8 @@ dec(1); // => 0

### drop

Returns the tail of `array` after dropping the first `n` elements
Returns the tail of `array` after dropping the first `n` elements.
Use this in place of String's `.substr(startIndex)` and `.substring(startIndex)`

```js
const drop = require('1-liners/drop');
Expand Down Expand Up @@ -865,6 +907,23 @@ inc(1); // => 2
</sup></div>


### indexOf

Same as `'str'.indexOf('t')`.

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

indexOf('a', 'hallo') // => 1
```

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


### isBetween

Check if the `number` lies between `min` and `max`, inclusive.
Expand Down Expand Up @@ -1245,6 +1304,23 @@ last([1, 2, 3]); // => 3
</sup></div>


### lastIndexOf

Same as `'wow'.lastIndexOf('w')`.

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

lastIndexOf('f', 'waffle') // => 3
```

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


### length

Returns the length of an array.
Expand Down Expand Up @@ -1826,6 +1902,25 @@ signum(-0); // => 0
</sup></div>


### slice

Same as `'1-liners'.slice(2,4)` or `[1,2,3,4].slice(1,3)`
Use in place of `'1-liners'.substring(2,6)`

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

slice(2, 6, '1-liners'); // => 'line'
slice(1, 3, [1,2,3,4]); // => [2,3]
```

<div align="right"><sup>
<a href="../tests/slice.js">Spec</a>
<a href="../module/slice.js">Source</a>: <code> (startIndex, endIndex, arg) =&gt; arg.slice(Math.max(startIndex, 0), endIndex);</code>
</sup></div>


### some

Same as `[1,2,3].some(GreaterThan16)`
Expand Down Expand Up @@ -2018,6 +2113,40 @@ times(3, 2); // => 6
</sup></div>


### toLowerCase

Same as `'STR'.toLowerCase()`.

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

toLowerCase('HALLO') // => 'hallo'
```

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


### toUpperCase

Same as `'str'.toUpperCase()`.

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

toUpperCase('hallo') // => 'HALLO'
```

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


### uncurry

Uncurry a function – collapse 2 lists of parameters into one.
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);
3 changes: 2 additions & 1 deletion module/drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*
* @description
*
* Returns the tail of `array` after dropping the first `n` elements
* Returns the tail of `array` after dropping the first `n` elements.
* Use this in place of String's `.substr(startIndex)` and `.substring(startIndex)`
*
* @example
*
Expand Down
14 changes: 14 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 @@ -37,6 +39,7 @@ import ifThen from './ifThen';
import ifThenElse from './ifThenElse';
import implode from './implode';
import inc from './inc';
import indexOf from './indexOf';
import isBetween from './isBetween';
import isBoolean from './isBoolean';
import isFalse from './isFalse';
Expand All @@ -55,6 +58,7 @@ import isUnknown from './isUnknown';
import join from './join';
import keys from './keys';
import last from './last';
import lastIndexOf from './lastIndexOf';
import length from './length';
import lessOrEqual from './lessOrEqual';
import lessThan from './lessThan';
Expand Down Expand Up @@ -86,6 +90,7 @@ import replace from './replace';
import shallowClone from './shallowClone';
import shave from './shave';
import signum from './signum';
import slice from './slice';
import some from './some';
import split from './split';
import startsWith from './startsWith';
Expand All @@ -97,6 +102,8 @@ import takeUntil from './takeUntil';
import takeWhile from './takeWhile';
import test from './test';
import times from './times';
import toLowerCase from './toLowerCase';
import toUpperCase from './toUpperCase';
import uncurry from './uncurry';
import uncurry3 from './uncurry3';
import values from './values';
Expand All @@ -112,6 +119,8 @@ export {
bitOr,
butLast,
by,
charCodeAt,
codePointAt,
compose,
composeAll,
concat,
Expand Down Expand Up @@ -142,6 +151,7 @@ export {
ifThenElse,
implode,
inc,
indexOf,
isBetween,
isBoolean,
isFalse,
Expand All @@ -160,6 +170,7 @@ export {
join,
keys,
last,
lastIndexOf,
length,
lessOrEqual,
lessThan,
Expand Down Expand Up @@ -191,6 +202,7 @@ export {
shallowClone,
shave,
signum,
slice,
some,
split,
startsWith,
Expand All @@ -202,6 +214,8 @@ export {
takeWhile,
test,
times,
toLowerCase,
toUpperCase,
uncurry,
uncurry3,
values,
Expand Down
15 changes: 15 additions & 0 deletions module/indexOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @module 1-liners/indexOf
*
* @description
*
* Same as `'str'.indexOf('t')`.
*
* @example
*
* var indexOf = require('1-liners/indexOf');
*
* indexOf('a', 'hallo') // => 1
*
*/
export default (searchValue, str) => str.indexOf(searchValue);
15 changes: 15 additions & 0 deletions module/lastIndexOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @module 1-liners/lastIndexOf
*
* @description
*
* Same as `'wow'.lastIndexOf('w')`.
*
* @example
*
* var lastIndexOf = require('1-liners/lastIndexOf');
*
* lastIndexOf('f', 'waffle') // => 3
*
*/
export default (searchValue, str) => str.lastIndexOf(searchValue);
17 changes: 17 additions & 0 deletions module/slice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @module 1-liners/slice
*
* @description
*
* Same as `'1-liners'.slice(2,4)` or `[1,2,3,4].slice(1,3)`
* Use in place of `'1-liners'.substring(2,6)`
*
* @example
*
* var slice = require('1-liners/slice');
*
* slice(2, 6, '1-liners'); // => 'line'
* slice(1, 3, [1,2,3,4]); // => [2,3]
*
*/
export default (startIndex, endIndex, arg) => arg.slice(Math.max(startIndex, 0), endIndex);
Loading

0 comments on commit 091e287

Please sign in to comment.