LCOV - code coverage report
Current view: top level - src/core - index.js (source / functions) Hit Total Coverage
Test: cov_profile.lcov Lines: 51 51 100.0 %
Date: 2021-12-16 00:47:58 Functions: 6 6 100.0 %
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
       1                 :         42 : import config from "./config.js";
       2            [ + ]:         42 : import { Register, registered } from "./register/index.js";
       3                 :         42 : import Prng from "./prng/index.js";
       4                 :         42 : import Moon from "./moon.js";
       5                 :         42 : import number from "./primitives/number/number.js";
       6                 :         42 : import object from "./primitives/object/object.js";
       7                 :         42 : import json from "./primitives/json/json.js";
       8                 :         42 : import array from "./primitives/array/array.js";
       9                 :         42 : import string from "./primitives/string/string.js";
      10                 :         42 : 
      11                 :         42 : const Fiona = (seed, path = []) => new Moon(Prng, seed, path);
      12                 :         42 : 
      13                 :         42 : Fiona.version = config.version;
      14                 :         42 : 
      15                 :         42 : // TODO: would it be simpler to pull the Register factory into core index?
      16                 :         42 : const registerFactory = (name, fn) => {
      17                 :        472 :   const fnProxy = (...args) => fn(...args);
      18                 :        472 :   // TODO: handle duplicate extension registrations
      19                 :        472 :   registered.push(fnProxy);
      20                 :        472 :   return (Fiona[name] = fnProxy);
      21                 :         42 : };
      22                 :         42 : 
      23                 :         42 : const registerMethod = (name, fn) => {
      24                 :        472 :   return (Moon.prototype[name] = fn);
      25                 :         42 : };
      26                 :         42 : 
      27                 :         42 : // TODO: should it be possible to register extensions local to seeded instance?
      28                 :         42 : // perhaps something like:
      29                 :         42 : //     const personExtension = seeded => ({
      30                 :         42 : //       gender: Fiona.Gender,
      31                 :         42 : //       name: ({ data }) => seeded.fullname({ gender: data.gender })
      32                 :         42 : //     })
      33                 :         42 : //     Fiona().register(['person', personExtension]).object(() => Fiona.Person, { luckyNumber: Fiona.Number({ max: 100 }) })
      34                 :         42 : Fiona.register = Register(registerFactory, registerMethod);
      35                 :         42 : 
      36                 :         42 : // TODO: register Random on seeded instance, perhaps need to implement seeded.register first
      37                 :         42 : Fiona.Random = () => (seeded) => seeded.random();
      38            [ + ]:         42 : 
      39                 :         42 : const clone = (seeded) => Fiona(seeded.info().initseed).state(seeded.state());
      40                 :         42 : 
      41                 :         42 : Fiona.register(["clone", clone]);
      42                 :         42 : 
      43                 :         42 : Fiona.register(
      44                 :         42 :   ["number", number],
      45                 :         42 :   ["object", object],
      46                 :         42 :   ["json", json],
      47                 :         42 :   ["string", string],
      48                 :         42 :   ["array", array],
      49                 :         42 : );
      50                 :         42 : 
      51                 :         21 : export default Fiona;

Generated by: LCOV version 1.15