-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { convertStringMethod } from './convertStringMethod' | ||
|
||
/** | ||
* Replaces by a slice of former string starting at <code>beginIndex</code> and ending at <code>endIndex</code> or end of the string. | ||
* @function | ||
* @memberof string | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {number} beginIndex Beginning index of slice. | ||
* @param {number?} endIndex Ending index of slice. | ||
* @return {Object} Returns the updated object. | ||
* @example slice({ nested: { a: 'Hello World !' } }, 6) // => { nested: { a: 'World !' } } | ||
* @example slice({ nested: { a: 'Hello World !' } }, 6, 11) // => { nested: { a: 'World' } } | ||
* @see {@link https://mdn.io/String.prototype.slice|String.prototype.slice} for more information. | ||
* @since 1.0.0 | ||
* @flow | ||
*/ | ||
const slice = convertStringMethod('slice') | ||
|
||
export { slice } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { slice } from 'string' | ||
|
||
describe('string.slice', () => { | ||
|
||
it('should return a slice to the end', () => { | ||
immutaTest((input, path) => { | ||
const output = slice(input, path, 6) | ||
expect(output).toEqual({ nested: { prop: 'World !' } }) | ||
return output | ||
}, { nested: { prop: 'Hello World !' } }, 'nested.prop') | ||
}) | ||
|
||
it('should return a slice to the end', () => { | ||
immutaTest((input, path) => { | ||
const output = slice(input, path, 6, 11) | ||
expect(output).toEqual({ nested: { prop: 'World' } }) | ||
return output | ||
}, { nested: { prop: 'Hello World !' } }, 'nested.prop') | ||
}) | ||
}) |