Skip to content

Commit

Permalink
Merge pull request #1 from armanozak/fix/return-default-value-when-la…
Browse files Browse the repository at this point in the history
…st-key-not-found

Return default value when last key not found
  • Loading branch information
armanozak committed Jun 28, 2019
2 parents ac0dd29 + 1cfc501 commit e5d4ddc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "snq",
"version": "1.0.2",
"version": "1.0.3",
"author": "Levent Arman Özak <arman@armanozak.com>",
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion src/snq.ts
@@ -1,6 +1,7 @@
export default function snq<T = any>(callback: () => T, defaultValue?: T) {
try {
return callback();
const result = callback();
return typeof result === 'undefined' ? defaultValue : result;
} catch (err) {
if (err instanceof TypeError) {
return defaultValue;
Expand Down

0 comments on commit e5d4ddc

Please sign in to comment.