Skip to content

Commit

Permalink
Merge pull request #176 from dhershman1/dev
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
dhershman1 authored Mar 19, 2024
2 parents f20cf57 + faa9e29 commit a03bd61
Show file tree
Hide file tree
Showing 31 changed files with 1,223 additions and 655 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## v3.0.0

### Breaking Changes

- `update` now uses `adjust` under the hood which gives it all the same rules
- Meaning it will also return the list back with an out of bounds index

### New

- Added some a new test to `find` to test Set Data types
- Added new `adjust` function which applies a function to a supplied array data at a provided index
- Added new `keys` function which takes the keys of a provided object and gives them back as an array

### Improved

- `values` now uses the built in `keys` function instead of `Object.keys`
- `draft` now uses the built in `keys` function instead of `Object.keys`
- Converted `any`, `omit`, `omitBy`, `plan`, `sift`, `whole`, and `withDefaults` to use `keys` instead of `Object.keys`
- Greatly expanded the unit testing around `values`
- Expanded the unit tests for `groupBy`
- Expanded the unit tests for `gt` and `gte`
- Expanded the unit tests for `difference`
- Added an extra unit test for `plan`

### Fixed

- Documentation link in readme now goes to kyanites website instead of 404ing

## v2.1.0

### New
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Because I think mineral names are cool
## Contents

- [View the Changelog](https://github.com/dhershman1/kyanite/blob/master/CHANGELOG.md)
- [View the Documentation](https://dhershman1.github.io/kyanite/)
- [View the Documentation](https://kyanite.dusty.codes)
- [Philosophy](#philosophy)
- [Key Features](#key-features)
- [How To](#how-to)
Expand Down
1,468 changes: 842 additions & 626 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kyanite",
"version": "2.1.0",
"version": "3.0.0",
"description": "A small library of pure functional utilities to make life easier and data better",
"main": "dist/kyanite.min.cjs",
"type": "module",
Expand Down Expand Up @@ -30,20 +30,20 @@
}
},
"devDependencies": {
"@babel/core": "7.23.5",
"@babel/core": "7.24.0",
"@babel/plugin-transform-object-assign": "7.23.3",
"@babel/preset-env": "7.23.5",
"@babel/preset-env": "7.24.0",
"@rollup/plugin-babel": "6.0.4",
"@rollup/plugin-terser": "0.4.4",
"globby": "13.2.2",
"jsdoc": "4.0.2",
"npm-run-all": "4.1.5",
"pinet": "1.1.4",
"rollup": "4.7.0",
"pinet": "1.1.5",
"rollup": "4.13.0",
"rollup-plugin-filesize": "10.0.0",
"standard": "17.1.0",
"tap-on": "1.0.0",
"tape": "5.7.2"
"tape": "5.7.5"
},
"scripts": {
"test": "tape tests/**/*.js | tap-on -u",
Expand Down
41 changes: 41 additions & 0 deletions src/array/adjust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import _curry3 from '../_internals/_curry3.js'

/**
* @name adjust
* @since v3.0.0
* @function
* @category Array
* @sig Number -> (a -> a) -> [a] -> [a]
* @description Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application.
* @param {Number} idx The index the value we want to change is at
* @param {Function} fn The function to apply
* @param {Array} list The array of data
* @return {Array} A copy of the supplied array with the element at index `idx` replaced with the value returned by applying `fn` to the existing element.
* @example
* import { adjust, inc, toUpper } from 'kyanite'
*
* adjust(1, inc, [0, 1, 2, 3]) // => [0, 2, 2, 3]
* adjust(1, toUpper, ['a', 'b', 'c']) // => ['a', 'B', 'c']
*
* // adjust can also be curried
*
* const fn = adjust(1)
*
* fn(toUpper, ['a', 'b', 'c']) // => ['a', 'B', 'c]
*/
const adjust = (idx, fn, list) => {
const len = list.length

if (idx >= len || idx < -len) {
return list
}

const _idx = (len + idx) % len
const _list = [...list]

_list[_idx] = fn(_list[_idx])

return _list
}

export default _curry3(adjust)
12 changes: 6 additions & 6 deletions src/array/update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import concatMap from './concatMap.js'
import _curry3 from '../_internals/_curry3.js'
import identity from '../function/identity.js'
import adjust from './adjust.js'
import always from '../function/always.js'

/**
* @name update
Expand All @@ -9,15 +9,16 @@ import identity from '../function/identity.js'
* @category Array
* @sig Number -> a -> [b] -> [c]
* @description Add an item to an array within a certain index of the array
* @param {Number} index The index number to add at
* @param {Number} idx The index number to add at
* @param {Any} val What we want to add to our array
* @param {Array} list The array in question
* @return {Array} Returns the modified array
*
* @example
* import { update } from 'kyanite'
*
* update(2, 10, [1, 2, 3]) // => [1, 2, 10]
* update(1, 10, [1, 2, 3]) // => [1, 10, 3]
* update(-1, 10, [1, 2, 3]) // => [1, 2, 10]
*
* // You can also use it as a curried method
*
Expand All @@ -31,7 +32,6 @@ import identity from '../function/identity.js'
* const val = index(10)
* val([1, 2, 3]) // => [1, 2, 10]
*/
const update = (index, val, list) =>
concatMap(identity, [list.slice(0, index), val, list.slice(index + 1)])
const update = (idx, val, list) => adjust(idx, always(val), list)

export default _curry3(update)
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as adjust } from './array/adjust.js'
export { default as chunk } from './array/chunk.js'
export { default as concatMap } from './array/concatMap.js'
export { default as countBy } from './array/countBy.js'
Expand Down Expand Up @@ -133,6 +134,7 @@ export { default as amend } from './object/amend.js'
export { default as any } from './object/any.js'
export { default as draft } from './object/draft.js'
export { default as height } from './object/height.js'
export { default as keys } from './object/keys.js'
export { default as omit } from './object/omit.js'
export { default as omitBy } from './object/omitBy.js'
export { default as over } from './object/over.js'
Expand Down
3 changes: 2 additions & 1 deletion src/object/any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _curry2 from '../_internals/_curry2.js'
import keys from './keys.js'

/**
* @name any
Expand All @@ -23,7 +24,7 @@ import _curry2 from '../_internals/_curry2.js'
* run({ a: 'xxx', b: 'bar' }) // => false
*/
const any = (schema, obj) =>
Object.keys(schema).some(key =>
keys(schema).some(key =>
schema[key](obj[key]))

export default _curry2(any)
3 changes: 2 additions & 1 deletion src/object/draft.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _curry2 from '../_internals/_curry2.js'
import _assocǃ from '../_internals/_assocǃ.js'
import _reduce from '../_internals/_reduce.js'
import keys from './keys.js'

/**
* @name draft
Expand All @@ -25,6 +26,6 @@ import _reduce from '../_internals/_reduce.js'
*/
const draft = (fn, obj) =>
_reduce((key, acc) =>
_assocǃ(acc, key, fn(obj[key])), {}, Object.keys(obj))
_assocǃ(acc, key, fn(obj[key])), {}, keys(obj))

export default _curry2(draft)
36 changes: 36 additions & 0 deletions src/object/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @name keys
* @function
* @since v3.0.0
* @category Object
* @sig { k: v } -> [k]
* @description Returns a list of all the own properties of an object
* @param {Object} obj The object we want to pull the keys from
* @return {Array} Returns an array of keys from the provided object
*
* @example
* import { keys } from 'kyanite'
*
* keys({ a: 1, b: 2, c: 3, d: { x: 100, y: 200 } }) // => ['a', 'b', 'c', 'd']
*/
const keys = obj => {
if (typeof Object.keys === 'function') {
return Object(obj) !== obj ? [] : Object.keys(obj)
}

if (Object(obj) !== obj) {
return []
}

const ks = []

for (const prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop) && prop !== 'length') {
ks.push(prop)
}
}

return ks
}

export default keys
5 changes: 3 additions & 2 deletions src/object/omit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _curry2 from '../_internals/_curry2.js'
import includes from '../list/includes.js'
import not from '../function/not.js'
import _reduce from '../_internals/_reduce.js'
import keys from './keys.js'

/**
* @name omit
Expand All @@ -28,8 +29,8 @@ import _reduce from '../_internals/_reduce.js'
*
* omitKeys({ test: '3432', thing: 123 }) // => { thing: 123 }
*/
const omit = (keys, obj) =>
const omit = (ks, obj) =>
_reduce((prop, acc) =>
not(includes(prop, keys)) ? _assocǃ(acc, prop, obj[prop]) : acc, {}, Object.keys(obj))
not(includes(prop, ks)) ? _assocǃ(acc, prop, obj[prop]) : acc, {}, keys(obj))

export default _curry2(omit)
3 changes: 2 additions & 1 deletion src/object/omitBy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _curry2 from '../_internals/_curry2.js'
import _assocǃ from '../_internals/_assocǃ.js'
import _reduce from '../_internals/_reduce.js'
import keys from './keys.js'

/**
* @name omitBy
Expand All @@ -27,6 +28,6 @@ import _reduce from '../_internals/_reduce.js'
* omitKeys({ test: '3432', thing: 123 }) // => { thing: 123 }
*/
const omitBy = (fn, obj) =>
_reduce((k, acc) => fn(obj[k], k) ? _assocǃ(acc, k, obj[k]) : acc, {}, Object.keys(obj))
_reduce((k, acc) => fn(obj[k], k) ? _assocǃ(acc, k, obj[k]) : acc, {}, keys(obj))

export default _curry2(omitBy)
3 changes: 2 additions & 1 deletion src/object/plan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _curry2 from '../_internals/_curry2.js'
import _assocǃ from '../_internals/_assocǃ.js'
import _reduce from '../_internals/_reduce.js'
import keys from './keys.js'

/**
* @name plan
Expand Down Expand Up @@ -30,6 +31,6 @@ import _reduce from '../_internals/_reduce.js'
*/
const plan = (schema, obj) =>
Object.assign({}, obj, _reduce((k, acc) =>
!Object.prototype.hasOwnProperty.call(obj, k) ? acc : _assocǃ(acc, k, schema[k](obj[k])), {}, Object.keys(schema)))
!Object.prototype.hasOwnProperty.call(obj, k) ? acc : _assocǃ(acc, k, schema[k](obj[k])), {}, keys(schema)))

export default _curry2(plan)
3 changes: 2 additions & 1 deletion src/object/sift.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _curry2 from '../_internals/_curry2.js'
import _assocǃ from '../_internals/_assocǃ.js'
import _reduce from '../_internals/_reduce.js'
import keys from './keys.js'

/**
* @name sift
Expand Down Expand Up @@ -30,6 +31,6 @@ import _reduce from '../_internals/_reduce.js'
* sifter({ id: 44, thing: 'test', other: 'cool' }) // => { thing: 'test', other: 'cool' }
*/
const sift = (fn, obj) => _reduce((k, acc) =>
fn(obj[k]) ? _assocǃ(acc, k, obj[k]) : acc, {}, Object.keys(obj))
fn(obj[k]) ? _assocǃ(acc, k, obj[k]) : acc, {}, keys(obj))

export default _curry2(sift)
3 changes: 2 additions & 1 deletion src/object/values.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _reduce from '../_internals/_reduce.js'
import _appendǃ from '../_internals/_appendǃ.js'
import keys from './keys.js'

/**
* @name values
Expand All @@ -16,6 +17,6 @@ import _appendǃ from '../_internals/_appendǃ.js'
* values({ a: 1, b: 2, c: 3 }) // => [1, 2, 3]
*/
const values = obj =>
_reduce((k, acc) => _appendǃ(acc, obj[k]), [], Object.keys(obj))
_reduce((k, acc) => _appendǃ(acc, obj[k]), [], keys(obj))

export default values
3 changes: 2 additions & 1 deletion src/object/whole.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _curry2 from '../_internals/_curry2.js'
import keys from './keys.js'

/**
* @name whole
Expand All @@ -20,7 +21,7 @@ import _curry2 from '../_internals/_curry2.js'
* run({ a: 'xxx', b: 'xxx', x: 11, y: 19 }) // => false
*/
const whole = (schema, obj) =>
Object.keys(schema).every(key =>
keys(schema).every(key =>
schema[key](obj[key]))

export default _curry2(whole)
3 changes: 2 additions & 1 deletion src/object/withDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _curry2 from '../_internals/_curry2.js'
import _assocǃ from '../_internals/_assocǃ.js'
import _reduce from '../_internals/_reduce.js'
import defaultTo from '../function/defaultTo.js'
import keys from './keys.js'

/**
* @name withDefaults
Expand Down Expand Up @@ -29,6 +30,6 @@ import defaultTo from '../function/defaultTo.js'
*/
const withDefaults = (def, obj) =>
_reduce((k, acc) =>
_assocǃ(acc, k, defaultTo(def[k], obj[k])), {}, Object.keys(def))
_assocǃ(acc, k, defaultTo(def[k], obj[k])), {}, keys(def))

export default _curry2(withDefaults)
Loading

0 comments on commit a03bd61

Please sign in to comment.