Comparing version 5.0.0 to 6.0.0-next.1585261338.530f8befc4f95e9c4d0a5b8d2cb859180e8323ff
@@ -0,1 +1,5 @@ | ||
/** Comparator for sorting fellows in an array */ | ||
export function comparator(a, b) { | ||
return a.compare(b) | ||
} | ||
/** A fellow with similarties to other people */ | ||
@@ -36,10 +40,39 @@ export default class Fellow { | ||
// ----------------------------------- | ||
// Construction | ||
// Methods | ||
/** | ||
* Compare a fellow to another fellow, uses {@link Fellow::idFields} for the comparison | ||
* If an ensureField is an array for both ourself and the other fellow, we will check to see if only one item of that array is similar (this is useful for email comparisons) | ||
* Sort a list of fellows. | ||
* Uses {@link Fellow::sort} for the comparison. | ||
*/ | ||
static sort(list) { | ||
return list.sort(comparator) | ||
} | ||
/** Flatten lists of fellows into one set of fellows */ | ||
static flatten(lists) { | ||
const fellows = new Set() | ||
for (const list of lists) { | ||
for (const fellow of list) { | ||
fellows.add(fellow) | ||
} | ||
} | ||
return fellows | ||
} | ||
/** Compare to another fellow for sorting. */ | ||
compare(other) { | ||
const A = this.name.toLowerCase() | ||
const B = other.name.toLowerCase() | ||
if (A === B) { | ||
return 0 | ||
} else if (A < B) { | ||
return -1 | ||
} else { | ||
return 1 | ||
} | ||
} | ||
/** | ||
* Compare to another fellow for equivalancy. | ||
* Uses {@link Fellow::idFields} for the comparison. | ||
* @param other The other fellow to compare ourselves with | ||
* @returns Returns `true` if they appear to be the same person, or `false` if not | ||
* @returns Returns `true` if they appear to be the same person, or `false` if not. | ||
*/ | ||
compare(other) { | ||
same(other) { | ||
for (const field of this.idFields) { | ||
@@ -69,3 +102,4 @@ const value = this[field] | ||
/** | ||
* With the value, see if an existing fellow exists in our singleton list property with the value, otherwise create a new fellow instance with the value and add them to our singleton list | ||
* With the value, see if an existing fellow exists in our singleton list property with the value, otherwise create a new fellow instance with the value and add them to our singleton list. | ||
* Uses {@link Fellow::same} for the comparison. | ||
* @param value The value to create a new fellow instance or find the existing fellow instance with | ||
@@ -78,3 +112,3 @@ * @param add Whether to add the created person to the list | ||
for (const existingFellow of this.fellows) { | ||
if (newFellow.compare(existingFellow)) { | ||
if (newFellow.same(existingFellow)) { | ||
return existingFellow.set(value) | ||
@@ -301,3 +335,3 @@ } | ||
} | ||
/** A singleton array attached to the class object that stores it's instances to enable convergence of data */ | ||
/** A singleton attached to the class that stores it's instances to enable convergence of data */ | ||
Fellow.fellows = [] |
'use strict' | ||
Object.defineProperty(exports, '__esModule', { value: true }) | ||
/** Comparator for sorting fellows in an array */ | ||
function comparator(a, b) { | ||
return a.compare(b) | ||
} | ||
exports.comparator = comparator | ||
/** A fellow with similarties to other people */ | ||
@@ -38,10 +43,39 @@ class Fellow { | ||
// ----------------------------------- | ||
// Construction | ||
// Methods | ||
/** | ||
* Compare a fellow to another fellow, uses {@link Fellow::idFields} for the comparison | ||
* If an ensureField is an array for both ourself and the other fellow, we will check to see if only one item of that array is similar (this is useful for email comparisons) | ||
* Sort a list of fellows. | ||
* Uses {@link Fellow::sort} for the comparison. | ||
*/ | ||
static sort(list) { | ||
return list.sort(comparator) | ||
} | ||
/** Flatten lists of fellows into one set of fellows */ | ||
static flatten(lists) { | ||
const fellows = new Set() | ||
for (const list of lists) { | ||
for (const fellow of list) { | ||
fellows.add(fellow) | ||
} | ||
} | ||
return fellows | ||
} | ||
/** Compare to another fellow for sorting. */ | ||
compare(other) { | ||
const A = this.name.toLowerCase() | ||
const B = other.name.toLowerCase() | ||
if (A === B) { | ||
return 0 | ||
} else if (A < B) { | ||
return -1 | ||
} else { | ||
return 1 | ||
} | ||
} | ||
/** | ||
* Compare to another fellow for equivalancy. | ||
* Uses {@link Fellow::idFields} for the comparison. | ||
* @param other The other fellow to compare ourselves with | ||
* @returns Returns `true` if they appear to be the same person, or `false` if not | ||
* @returns Returns `true` if they appear to be the same person, or `false` if not. | ||
*/ | ||
compare(other) { | ||
same(other) { | ||
for (const field of this.idFields) { | ||
@@ -71,3 +105,4 @@ const value = this[field] | ||
/** | ||
* With the value, see if an existing fellow exists in our singleton list property with the value, otherwise create a new fellow instance with the value and add them to our singleton list | ||
* With the value, see if an existing fellow exists in our singleton list property with the value, otherwise create a new fellow instance with the value and add them to our singleton list. | ||
* Uses {@link Fellow::same} for the comparison. | ||
* @param value The value to create a new fellow instance or find the existing fellow instance with | ||
@@ -80,3 +115,3 @@ * @param add Whether to add the created person to the list | ||
for (const existingFellow of this.fellows) { | ||
if (newFellow.compare(existingFellow)) { | ||
if (newFellow.same(existingFellow)) { | ||
return existingFellow.set(value) | ||
@@ -304,3 +339,3 @@ } | ||
exports.default = Fellow | ||
/** A singleton array attached to the class object that stores it's instances to enable convergence of data */ | ||
/** A singleton attached to the class that stores it's instances to enable convergence of data */ | ||
Fellow.fellows = [] |
# History | ||
## v6.0.0 2020 March 27 | ||
- Added `Fellow.flatten` and `Fellow.sort`, renamed `Fellow::compare` to `Fellow:same` and introduced a new `Fellow::compare` for sorting. | ||
## v5.0.0 2020 March 27 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "fellow", | ||
"version": "5.0.0", | ||
"version": "6.0.0-next.1585261338.530f8befc4f95e9c4d0a5b8d2cb859180e8323ff", | ||
"description": "Fellow is a package for creating people that can be unified by their shared values via a singleton list on the class", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/bevry/fellow", |
@@ -55,3 +55,3 @@ <!-- TITLE/ --> | ||
<script type="module"> | ||
import pkg from '//cdn.pika.dev/fellow/^5.0.0' | ||
import pkg from '//cdn.pika.dev/fellow/^6.0.0' | ||
</script> | ||
@@ -64,3 +64,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//unpkg.com/fellow@^5.0.0' | ||
import pkg from '//unpkg.com/fellow@^6.0.0' | ||
</script> | ||
@@ -73,3 +73,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//dev.jspm.io/fellow@5.0.0' | ||
import pkg from '//dev.jspm.io/fellow@6.0.0' | ||
</script> | ||
@@ -76,0 +76,0 @@ ``` |
@@ -0,1 +1,6 @@ | ||
/** Comparator for sorting fellows in an array */ | ||
export function comparator(a: Fellow, b: Fellow) { | ||
return a.compare(b) | ||
} | ||
/** A fellow with similarties to other people */ | ||
@@ -44,15 +49,46 @@ export default class Fellow { | ||
/** A singleton array attached to the class object that stores it's instances to enable convergence of data */ | ||
/** A singleton attached to the class that stores it's instances to enable convergence of data */ | ||
static readonly fellows: Array<Fellow> = [] | ||
// ----------------------------------- | ||
// Construction | ||
// Methods | ||
/** | ||
* Compare a fellow to another fellow, uses {@link Fellow::idFields} for the comparison | ||
* If an ensureField is an array for both ourself and the other fellow, we will check to see if only one item of that array is similar (this is useful for email comparisons) | ||
* Sort a list of fellows. | ||
* Uses {@link Fellow::sort} for the comparison. | ||
*/ | ||
static sort(list: Array<Fellow>) { | ||
return list.sort(comparator) | ||
} | ||
/** Flatten lists of fellows into one set of fellows */ | ||
static flatten(lists: Array<Array<Fellow> | Set<Fellow>>): Set<Fellow> { | ||
const fellows = new Set<Fellow>() | ||
for (const list of lists) { | ||
for (const fellow of list) { | ||
fellows.add(fellow) | ||
} | ||
} | ||
return fellows | ||
} | ||
/** Compare to another fellow for sorting. */ | ||
compare(other: Fellow): -1 | 0 | 1 { | ||
const A = this.name.toLowerCase() | ||
const B = other.name.toLowerCase() | ||
if (A === B) { | ||
return 0 | ||
} else if (A < B) { | ||
return -1 | ||
} else { | ||
return 1 | ||
} | ||
} | ||
/** | ||
* Compare to another fellow for equivalancy. | ||
* Uses {@link Fellow::idFields} for the comparison. | ||
* @param other The other fellow to compare ourselves with | ||
* @returns Returns `true` if they appear to be the same person, or `false` if not | ||
* @returns Returns `true` if they appear to be the same person, or `false` if not. | ||
*/ | ||
compare(other: Fellow): boolean { | ||
same(other: Fellow): boolean { | ||
for (const field of this.idFields) { | ||
@@ -84,3 +120,4 @@ const value = this[field] | ||
/** | ||
* With the value, see if an existing fellow exists in our singleton list property with the value, otherwise create a new fellow instance with the value and add them to our singleton list | ||
* With the value, see if an existing fellow exists in our singleton list property with the value, otherwise create a new fellow instance with the value and add them to our singleton list. | ||
* Uses {@link Fellow::same} for the comparison. | ||
* @param value The value to create a new fellow instance or find the existing fellow instance with | ||
@@ -93,3 +130,3 @@ * @param add Whether to add the created person to the list | ||
for (const existingFellow of this.fellows) { | ||
if (newFellow.compare(existingFellow)) { | ||
if (newFellow.same(existingFellow)) { | ||
return existingFellow.set(value) | ||
@@ -289,3 +326,3 @@ } | ||
/** Get all fellows who contribute to a particular repository */ | ||
static contributesRepository(repoSlug: string): Fellows { | ||
static contributesRepository(repoSlug: string): Array<Fellow> { | ||
return this.fellows.filter(function (fellow) { | ||
@@ -297,3 +334,3 @@ return fellow.contributedRepositories.has(repoSlug) | ||
/** Get all fellows who maintain a particular repository */ | ||
static maintainsRepository(repoSlug: string): Fellows { | ||
static maintainsRepository(repoSlug: string): Array<Fellow> { | ||
return this.fellows.filter(function (fellow) { | ||
@@ -305,3 +342,3 @@ return fellow.maintainedRepositories.has(repoSlug) | ||
/** Get all fellows who author a particular repository */ | ||
static authorsRepository(repoSlug: string): Fellows { | ||
static authorsRepository(repoSlug: string): Array<Fellow> { | ||
return this.fellows.filter(function (fellow) { | ||
@@ -347,3 +384,1 @@ return fellow.authoredRepositories.has(repoSlug) | ||
} | ||
export type Fellows = Array<Fellow> |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
51635
1021
1