Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
declare function findOnly<T>(array: ReadonlyArray<T>, predicate: (item: T) => boolean): T; | ||
declare function findOnly<T>(array: ReadonlyArray<T>, predicate: (item: T) => boolean, message?: string): T; | ||
export default findOnly; |
@@ -1,5 +0,5 @@ | ||
function findOnly(array, predicate) { | ||
function findOnly(array, predicate, message) { | ||
const found = array.filter(predicate); | ||
if (found.length !== 1) { | ||
throw new Error(`Expected exactly one item, found ${found.length}`); | ||
throw new Error(message ?? `Expected exactly one item, found ${found.length}`); | ||
} | ||
@@ -6,0 +6,0 @@ return found[0]; |
{ | ||
"name": "@dhau/lang", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Various language extensions for JS", | ||
@@ -19,3 +19,5 @@ "main": "./dist/index.js", | ||
"clean": "rm -rf", | ||
"build": "tsc --outDir dist" | ||
"build": "tsc --outDir dist", | ||
"publish": "npm publish --access public", | ||
"deploy": "run-s clean build publish" | ||
}, | ||
@@ -25,2 +27,3 @@ "author": "Daniel Holmes", | ||
"devDependencies": { | ||
"npm-run-all": "^4.1.5", | ||
"typescript": "^4.9.4" | ||
@@ -27,0 +30,0 @@ }, |
2680
2