This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Add string functions #87
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,16 @@ | ||
import _capitalize from 'lodash/capitalize' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Converts the first character of string to upper case and the remaining to lower case. | ||
* @function | ||
* @memberof object | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @return {Object} Returns the updated object. | ||
* @example capitalize({ nested: { a: "a string" } }, 'nested.a') // => { nested: { a: "A string" } } | ||
* @see {@link https://lodash.com/docs#capitalize|lodash.capitalize} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const capitalize = convert(_capitalize) | ||
export { capitalize, capitalize as default } |
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,14 @@ | ||
/* eslint-env jest */ | ||
import { capitalize } from './capitalize' | ||
import { immutaTest } from 'test.utils' | ||
|
||
describe('Capitalize', () => { | ||
|
||
it('should convert the first character of string to upper case and the remaining to lower case', () => { | ||
immutaTest((input, path) => { | ||
const output = capitalize(input, path) | ||
expect(output).toEqual({ nested: { prop: 'A string' } }) | ||
return output | ||
}, { nested: { prop: 'a string' } }, 'nested.prop') | ||
}) | ||
}) |
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,16 @@ | ||
import { capizalize } from './capizalize' | ||
import { replace } from './replace' | ||
import { toLower } from './toLower' | ||
import { toUpper } from './toUpper' | ||
|
||
/** | ||
* String functions. | ||
* @namespace string | ||
* @since 0.3.0 | ||
*/ | ||
export { | ||
capizalize, | ||
replace, | ||
toLower, | ||
toUpper, | ||
} |
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,18 @@ | ||
import _replace from 'lodash/replace' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Replaces matches for pattern in string with replacement. | ||
* @function | ||
* @memberof object | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {RegExp|string} pattern The pattern to replace. | ||
* @param {Function|string} replacement The match replacement. | ||
* @return {Object} Returns the updated object. | ||
* @example replace({ nested: { a: "Hi Nico" } }, 'nested.a', 'Nico', 'Yvo') // => { nested: { a: "Hi Yvo" } } | ||
* @see {@link https://lodash.com/docs#replace|lodash.replace} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const replace = convert(_replace) | ||
export { replace, replace as default } |
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,14 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { replace } from './replace' | ||
|
||
describe('Replace', () => { | ||
|
||
it('should replace matches for pattern in string with replacement', () => { | ||
immutaTest((input, path) => { | ||
const output = replace(input, path, 'Nico', 'Yvo') | ||
expect(output).toEqual({ nested: { prop: 'Hi Yvo' } }) | ||
return output | ||
}, { nested: { prop: 'Hi Nico' } }, 'nested.prop') | ||
}) | ||
}) |
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,17 @@ | ||
import _toLower from 'lodash/toLower' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Converts string, as a whole, to lower case just like String#toLowerCase. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add link to https://mdn.io/String/toLowerCase |
||
* @function | ||
* @memberof object | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @return {Object} Returns the updated object. | ||
* @example toLower({ nested: { a: "A STRING" } }, 'nested.a') // => { nested: { a: "a string" } } | ||
* @see {@link https://lodash.com/docs#toLower|lodash.toLower} for more information. | ||
* @see {@link https://mdn.io/String/toLowerCase|String.toLowerCase} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const toLower = convert(_toLower) | ||
export { toLower, toLower as default } |
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,14 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { toLower } from './toLower' | ||
|
||
describe('toLower', () => { | ||
|
||
it('should convert string, as a whole, to lower case just like String#toLowerCase', () => { | ||
immutaTest((input, path) => { | ||
const output = toLower(input, path) | ||
expect(output).toEqual({ nested: { prop: 'a string' } }) | ||
return output | ||
}, { nested: { prop: 'A STRING' } }, 'nested.prop') | ||
}) | ||
}) |
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,17 @@ | ||
import _toUpper from 'lodash/toUpper' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Converts string, as a whole, to upper case just like String#toUpperCase. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add link to https://mdn.io/String/toUpperCase |
||
* @function | ||
* @memberof object | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @return {Object} Returns the updated object. | ||
* @example toUpper({ nested: { a: "a string" } }, 'nested.a') // => { nested: { a: "A STRING" } } | ||
* @see {@link https://lodash.com/docs#toUpper|lodash.toUpper} for more information. | ||
* @see {@link https://mdn.io/String/toUpperCase|String.toUpperCase} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const toUpper = convert(_toUpper) | ||
export { toUpper, toUpper as default } |
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,14 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { toUpper } from './toUpper' | ||
|
||
describe('toUpper', () => { | ||
|
||
it('should convert string, as a whole, to upper case just like String#toUpperCase', () => { | ||
immutaTest((input, path) => { | ||
const output = toUpper(input, path) | ||
expect(output).toEqual({ nested: { prop: 'A STRING' } }) | ||
return output | ||
}, { nested: { prop: 'a string' } }, 'nested.prop') | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍺
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💩