Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Add string functions #87

Merged
merged 2 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './lang'
export * from './math'
export * from './object'
export * from './seq'
export * from './string'
export * from './util'
16 changes: 16 additions & 0 deletions src/string/capitalize.js
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 }
14 changes: 14 additions & 0 deletions src/string/capitalize.spec.js
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')
})
})
16 changes: 16 additions & 0 deletions src/string/index.js
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍺

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💩

replace,
toLower,
toUpper,
}
18 changes: 18 additions & 0 deletions src/string/replace.js
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 }
14 changes: 14 additions & 0 deletions src/string/replace.spec.js
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')
})
})
17 changes: 17 additions & 0 deletions src/string/toLower.js
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @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 }
14 changes: 14 additions & 0 deletions src/string/toLower.spec.js
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')
})
})
17 changes: 17 additions & 0 deletions src/string/toUpper.js
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @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 }
14 changes: 14 additions & 0 deletions src/string/toUpper.spec.js
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')
})
})