Skip to content

Commit

Permalink
Merge pull request #123 from dhershman1/development
Browse files Browse the repository at this point in the history
Development v0.14.0
  • Loading branch information
Dustin Hershman authored Jul 8, 2019
2 parents 07078b1 + 8b76e01 commit 39faf7b
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ All changes are expected to continue to pass the tests in place.

If you are adding new functionality to the library you are expected to also unit test and create appropriate testing for your additions

To run all tests use `npm t`

If you want to test only your functionality feel free to change the test script to your `.js` file but **please** remember to change it back to `*.js` and re run `npm t` afterwards!

## Documentation

For any new functionality additions please follow the format of other functionality in the form of jsdocs. The expected formatting should be:

```
```js
/**
* @name function name
* @function
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## v0.14.0

### BREAKING CHANGES

- Removed `memoizeWith` since it was more of a POC from ramda's code base
- I will most likely look into re adding it with my own code if the need is there right now I just don't see it

### New

- Added `startsWith` function, which should work just like `endsWith` but with the beginning of a list.

### Fixed

- `isPrime` should handle edge cases like 0 a correctly now and return false instead of 0 (#121)
- `endsWith` signature to reflect list instead of Array

## v0.13.0

### BREAKING CHANGES
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
</a>
</p>

## Why Kyanite?

Because I think mineral names are cool

## Contents

- [View the Changelog](https://github.com/dhershman1/kyanite/blob/master/CHANGELOG.md)
Expand Down Expand Up @@ -124,4 +128,4 @@ To run the tests:
A lot of the if not most of the inpiration for this library came from 2 libraries I follow closely, Primarily most of it stems from:

- [foreword](https://github.com/abstract-tools/foreword) by [Abstract Tools](https://github.com/abstract-tools) which is a very nice and easy to use library developed by a close friend and mentor. This is where a lot of functionality ideas came from I can't recommend it enough.
- [Ramdajs](http://ramdajs.com/) by [Ramda](https://github.com/ramda) a large and fairly handy library where the original idea sparked
- [Ramdajs](http://ramdajs.com/) by [Ramda](https://github.com/ramda) a beautiful and feature packed library where the original idea started
24 changes: 8 additions & 16 deletions dist/kyanite.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,18 +855,6 @@
};
var lte$1 = _curry2(lte);

var memoizeWith = function memoizeWith(mFn, fn) {
var cache = {};
return function (data) {
var key = mFn(data);
if (!has$1(key, cache)) {
cache[key] = fn(data);
}
return cache[key];
};
};
var memoizeWith$1 = _curry2(memoizeWith);

var notEq = function notEq(a, b) {
return complement$1(eq$1(a), b);
};
Expand Down Expand Up @@ -938,6 +926,11 @@
return Array.isArray(list) ? list.slice().reverse() : list.split('').reverse().join('');
};

var startsWith = function startsWith(a, list) {
return compose$1(deepEq$1(a), slice$1(0, a.length), list);
};
var startsWith$1 = _curry2(startsWith);

var add = function add(a, b) {
return a + b;
};
Expand Down Expand Up @@ -1012,13 +1005,12 @@

var isPrime = function isPrime(x) {
var s = Math.sqrt(x);
var i = 2;
for (i; i <= s; i++) {
for (var i = 2; i <= s; i++) {
if (!rem$1(i, x)) {
return false;
}
}
return x && x !== 1;
return x > 1;
};

var isZero = eq$1(0);
Expand Down Expand Up @@ -1320,7 +1312,6 @@
exports.maxBy = maxBy$1;
exports.mean = mean;
exports.median = median;
exports.memoizeWith = memoizeWith$1;
exports.min = min;
exports.minBy = minBy$1;
exports.mod = mod$1;
Expand Down Expand Up @@ -1365,6 +1356,7 @@
exports.sortBy = sortBy$1;
exports.sortWith = sortWith$1;
exports.split = split$1;
exports.startsWith = startsWith$1;
exports.subtract = subtract$1;
exports.sum = sum;
exports.take = take$1;
Expand Down
2 changes: 1 addition & 1 deletion dist/kyanite.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kyanite",
"version": "0.13.0",
"version": "0.14.0",
"description": "A small library of pure functional utilities to make life easier and data better",
"main": "dist/kyanite.min.js",
"module": "src/index.js",
Expand Down Expand Up @@ -36,7 +36,7 @@
"build": "rollup -c",
"create": "node scripts/create-export.js && standard --fix src/index.js",
"docs": "node_modules/.bin/jsdoc -c jsdoc.json",
"docs:deploy": "gh-pages --dist docs",
"docs:deploy": "gh-pages -m 'auto commit [ci skip]' --dist docs",
"scripts": "npm-run-all create build",
"test:cov": "nyc npm test",
"check-cov": "nyc check-coverage --lines 95 --functions 100 --branches 95",
Expand Down
43 changes: 0 additions & 43 deletions src/function/memoizeWith.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export { default as isEmpty } from './function/isEmpty.js'
export { default as isNil } from './function/isNil.js'
export { default as lt } from './function/lt.js'
export { default as lte } from './function/lte.js'
export { default as memoizeWith } from './function/memoizeWith.js'
export { default as not } from './function/not.js'
export { default as notEq } from './function/notEq.js'
export { default as on } from './function/on.js'
Expand All @@ -92,6 +91,7 @@ export { default as length } from './list/length.js'
export { default as nth } from './list/nth.js'
export { default as reverse } from './list/reverse.js'
export { default as slice } from './list/slice.js'
export { default as startsWith } from './list/startsWith.js'
export { default as add } from './number/add.js'
export { default as between } from './number/between.js'
export { default as clamp } from './number/clamp.js'
Expand Down
2 changes: 1 addition & 1 deletion src/list/endsWith.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import slice from './slice'
* @since v0.10.0
* @category List
* @sig
* a -> Array -> Boolean
* a -> List -> Boolean
* String -> String -> Boolean
* @description Checks to see if the provided value is at the end of a given list
* @param {String|Array} a The value to check for at the end of the list
Expand Down
34 changes: 34 additions & 0 deletions src/list/startsWith.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import compose from '../function/compose'
import _curry2 from '../_internals/_curry2'
import deepEq from '../function/deepEq'
import slice from './slice'

/**
* @name startsWith
* @function
* @since v0.14.0
* @category List
* @sig
* a -> List -> Boolean
* String -> String -> Boolean
* @description Checks to see if the provided value is at the beginning of a given list
* @param {String|Array} a The value to check for at the beginning of the list
* @param {String|Array} list The list to check through
* @return {Boolean} If the value is at the end of the provided list
* @example
* import { startsWith } from 'kyanite'
*
* startsWith('c' , 'cab') // => true
* startsWith(['c'], ['c', 'b', 'a']) // => true
* startsWith('b', 'abc') // => false
* startsWith(['b'], ['a', 'b', 'c']) // => false
*
* // It's also curried
* const fn = startsWith('c')
*
* fn('cab') // => true
* fn('abc') // => false
*/
const startsWith = (a, list) => compose(deepEq(a), slice(0, a.length), list)

export default _curry2(startsWith)
5 changes: 2 additions & 3 deletions src/number/isPrime.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import rem from './rem'
*/
const isPrime = x => {
const s = Math.sqrt(x)
let i = 2

for (i; i <= s; i++) {
for (let i = 2; i <= s; i++) {
if (!rem(i, x)) {
return false
}
}

return x && x !== 1
return x > 1
}

export default isPrime
21 changes: 0 additions & 21 deletions tests/function/memoizeWith.js

This file was deleted.

18 changes: 18 additions & 0 deletions tests/list/startsWith.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import startsWith from '../../src/list/startsWith'
import test from 'tape'

test('startsWith -- Basic Usage on lists', t => {
t.true(startsWith('c', 'cab'))
t.true(startsWith(['a'], ['a', 'b', 'c']))
t.false(startsWith('b', 'abc'))
t.end()
})

test('startsWith -- Is curried', t => {
const fn = startsWith('c')

t.true(fn('cab'))
t.true(fn('c'))
t.false(fn('a'))
t.end()
})
26 changes: 14 additions & 12 deletions tests/number/isPrime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import isPrime from '../../src/number/isPrime'
import test from 'tape'

test('isPrime -- Basic functionality', t => {
t.true(isPrime(2))
t.true(isPrime(5))
t.true(isPrime(3))
t.false(isPrime(4))
t.same(isPrime(2), true)
t.same(isPrime(5), true)
t.same(isPrime(3), true)
t.same(isPrime(4), false)

t.end()
})

test('isPrime -- Larger numbers', t => {
t.true(isPrime(2671))
t.true(isPrime(5009))
t.true(isPrime(7877))
t.false(isPrime(7878))
t.false(isPrime(5010))
t.same(isPrime(2671), true)
t.same(isPrime(5009), true)
t.same(isPrime(7877), true)
t.same(isPrime(7878), false)
t.same(isPrime(5010), false)
t.end()
})

test('isPrime -- Handles zero & NaN', t => {
t.false(isPrime(0))
t.false(isPrime(NaN))
test('isPrime -- Handles some edge cases', t => {
t.same(isPrime(0), false)
t.same(isPrime(undefined), false)
t.same(isPrime(NaN), false)
t.same(isPrime(-2), false)

t.end()
})

0 comments on commit 39faf7b

Please sign in to comment.