Comparing version 2.1.0 to 2.2.0
@@ -34,4 +34,8 @@ import { Mappable } from '../index'; | ||
*/ | ||
reject(callback: (item: T) => boolean): Arrayable<T>; | ||
reject(callback: (item: T, index?: number) => boolean): Arrayable<T>; | ||
/** | ||
* Moves an item in the array using the given source index to either "before" or "after" the given target. | ||
*/ | ||
move(source: number, position: 'before' | 'after', target: number): T[]; | ||
/** | ||
* Breaks the array into multiple, smaller arrays of a given size. | ||
@@ -68,2 +72,10 @@ */ | ||
prepend(...items: T[]): Arrayable<T>; | ||
/** | ||
* Returns value for current pointer position. | ||
*/ | ||
value(): T; | ||
/** | ||
* Steps forward or backward given the number of steps. | ||
*/ | ||
step(steps: number): any; | ||
}; | ||
@@ -70,0 +82,0 @@ /** |
@@ -64,5 +64,19 @@ "use strict"; | ||
reject(callback) { | ||
return this.filter(item => !callback(item)); | ||
return this.filter((item, index) => !callback(item, index)); | ||
} | ||
/** | ||
* Moves an item in the array using the given source index to either "before" or "after" the given target. | ||
*/ | ||
move(source, position, target) { | ||
if (source === target) { | ||
return this; | ||
} | ||
const comparison = position === 'before' ? (_, index) => index < target : (_, index) => index <= target; | ||
const [before, after] = this.partition(comparison); | ||
const result = before.concat(this[source], ...after); | ||
const newSourceIndex = source > target ? source + 1 : source; | ||
result.splice(newSourceIndex, 1); | ||
return result; | ||
} | ||
/** | ||
* Breaks the array into multiple, smaller arrays of a given size. | ||
@@ -128,2 +142,14 @@ */ | ||
return array.constructor.from([...before, ...items, ...after]); | ||
}, | ||
/** | ||
* Returns value for current pointer position. | ||
*/ | ||
value() { | ||
return array[index]; | ||
}, | ||
/** | ||
* Steps forward or backward given the number of steps. | ||
*/ | ||
step(steps) { | ||
return array.at(index + steps); | ||
} | ||
@@ -130,0 +156,0 @@ }; |
@@ -17,2 +17,6 @@ import Arrayable from './Arrayable'; | ||
/** | ||
* Renames the given key with the new key if found, keeping the original insertion order. | ||
*/ | ||
rename(oldKey: K, newKey: K): any; | ||
/** | ||
* Iterates the entries through the given callback and assigns each result as the value. | ||
@@ -19,0 +23,0 @@ */ |
@@ -49,2 +49,10 @@ "use strict"; | ||
/** | ||
* Renames the given key with the new key if found, keeping the original insertion order. | ||
*/ | ||
rename(oldKey, newKey) { | ||
return this.mapKeys((_, key) => { | ||
return (key === oldKey) ? newKey : key; | ||
}); | ||
} | ||
/** | ||
* Iterates the entries through the given callback and assigns each result as the value. | ||
@@ -51,0 +59,0 @@ */ |
{ | ||
"name": "flooent", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Fluent interface to provide an expressive syntax for common manipulations.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -690,2 +690,28 @@ # flooent | ||
#### value | ||
Returns the value for current pointer position. | ||
```javascript | ||
given.array(['music', 'tech']).at(1).value() // ['music', 'tech'] | ||
``` | ||
#### step | ||
Steps forward or backwards given the number of steps. | ||
```javascript | ||
given.array(['music', 'tec']).at(1).step(-1).value() // ['music'] | ||
``` | ||
#### move | ||
Moves an item in the array using the given source index to either "before" or "after" the given target. | ||
```javascript | ||
given.array(['b', 'a', 'c']).move(0, 'after', 1) // ['a', 'b', 'c'] | ||
given.array(['b', 'a', 'c']).move(0, 'before', 2) // ['a', 'b', 'c'] | ||
given.array(['b', 'a', 'c']).move(1, 'before', 0) // ['a', 'b', 'c'] | ||
``` | ||
### Methods for arrays of objects | ||
@@ -942,2 +968,12 @@ | ||
### rename | ||
Renames the given key with the new key if found, keeping the original insertion order. | ||
```javascript | ||
given.map({ one: 1, to: 2, three: 3 }) | ||
.rename('to', 'two') | ||
.keys() // ['one', 'two', 'three'] | ||
``` | ||
## Numbers | ||
@@ -944,0 +980,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73636
1353
1207