{"size": 759, "ext": "js", "max_stars_repo_path": "__tests__/dataGet.js", "max_stars_repo_name": "risan/helpers", "max_stars_repo_stars_event_min_datetime": "2020-02-14T16:42:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-14T17:16:13.000Z", "max_issues_repo_path": "__tests__/dataGet.js", "max_issues_repo_name": "risan/helpers", "max_issues_repo_issues_event_min_datetime": "2020-06-02T06:39:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T23:32:56.000Z", "max_forks_repo_path": "__tests__/dataGet.js", "max_forks_repo_name": "risan/helpers", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 5, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 36.1428571429, "max_line_length": 66, "alphanum_fraction": 0.5678524374}
/* global expect:false, test:false */
import { dataGet } from '../src';

test('it can retrieve value by path', () => {
  expect(dataGet({ foo: 'bar' }, 'foo')).toBe('bar');
  expect(dataGet({ foo: { bar: 'baz' } }, 'foo.bar')).toBe('baz');
  expect(dataGet([1, 2, 3], '[1]')).toBe(2);
  expect(dataGet({ foo: [1, 2, 3] }, 'foo.[1]')).toBe(2);
  expect(dataGet([{}, { id: 123 }], '[1].id')).toBe(123);
});

test('it returns undefined if path does not exists', () => {
  expect(dataGet({ foo: 'bar' }, 'baz')).toBe(undefined);
  expect(dataGet({ foo: null }, 'foo')).toBeNull();
  expect(dataGet({ foo: undefined }, 'foo')).toBe(undefined);
});

test('it can accept a custom fallback value', () => {
  expect(dataGet({ foo: 'bar' }, 'baz', 123)).toBe(123);
});
