npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adab-silsilah-tree

v1.0.0

Published

Family tree management library

Downloads

9

Readme

ADABsilsilah Documentation

Introduction

ADABsilsilah is a JavaScript library designed for managing and documenting family lineage. It allows you to create and manipulate a family tree, add members with relationships, manage special events, search for members, and export/import data in CSV format.

Installation

You can install ADABsilsilah via npm:

npm install adab-silsilah-tree

Usage

Importing the Library

import ADABsilsilah from 'adab-silsilah-tree';

// Example data for the root member
const rootMemberData = {
  id: 1,
  name: 'John Doe',
  gender: 'male',
  birthDate: '1980-01-01',
  phone: '1234567890' // Optional: phone number
};

// Initialize the family tree with the root member
const familyTree = new ADABsilsilah(rootMemberData);

Class: ADABsilsilah

Constructor: new ADABsilsilah(rootMember)

Initializes a new instance of ADABsilsilah with the root member specified.

  • Parameters:
    • rootMember (Object): Data of the root member containing id, name, gender, birthDate, and optionally phone.

Methods:

  1. addMember(member, relationship, relativeId)

    Adds a new member to the family tree with a specified relationship to an existing member.

    • Parameters:
      • member (Object): Data of the new member to be added.
      • relationship (String): Relationship type (child, sibling, spouse).
      • relativeId (Number): ID of the existing member to relate to.
    const newMemberData = {
      id: 2,
      name: 'Jane Doe',
      gender: 'female',
      birthDate: '1985-03-15',
      phone: '9876543210' // Optional: phone number
    };
    
    familyTree.addMember(newMemberData, 'child', 1); // Adds Jane Doe as a child of John Doe
  2. removeMember(memberId)

    Removes a member from the family tree.

    • Parameters:
      • memberId (Number): ID of the member to be removed.
    familyTree.removeMember(2); // Removes Jane Doe from the family tree
  3. updateMember(memberId, updatedInfo)

    Updates information of an existing member in the family tree.

    • Parameters:
      • memberId (Number): ID of the member to be updated.
      • updatedInfo (Object): Updated data fields for the member.
    const updatedInfo = {
      name: 'Jane Doe-Smith',
      phone: '9876543210'
    };
    
    familyTree.updateMember(2, updatedInfo); // Updates Jane Doe's name and phone number
  4. addEvent(memberId, event)

    Adds a special event to a member, such as birth, death, marriage, etc.

    • Parameters:
      • memberId (Number): ID of the member to add the event to.
      • event (String): Description of the event.
    familyTree.addEvent(2, 'Married John Smith'); // Adds a marriage event to Jane Doe-Smith
  5. findMember(memberId)

    Finds a member in the family tree based on their ID.

    • Parameters:

      • memberId (Number): ID of the member to find.
    • Returns:

      • FamilyMember object or null if not found.
    const member = familyTree.findMember(2);
    if (member) {
      console.log(`Found member: ${member.name}`);
    } else {
      console.log('Member not found');
    }
  6. searchMembers(query)

    Searches for members in the family tree based on a query (name or gender).

    • Parameters:

      • query (String): Search query.
    • Returns:

      • Array of FamilyMember objects that match the query.
    const results = familyTree.searchMembers('Jane');
    console.log('Search results:', results);
  7. exportToCSV()

    Exports the family tree data to a CSV format string.

    • Returns:
      • CSV format string containing member details.
    const csvData = familyTree.exportToCSV();
    console.log('Exported CSV data:', csvData);
  8. importFromCSV(csvData)

    Imports family tree data from a CSV format string.

    • Parameters:
      • csvData (String): CSV format data to import.
    const csvData = `
      ID,Name,Gender,BirthDate,DeathDate,Parents,Children,Siblings,Spouse,Phone
      1,"John Doe",male,1980-01-01,,2,,,,1234567890
      2,"Jane Doe-Smith",female,1985-03-15,,,1,,1,9876543210
    `;
    
    familyTree.importFromCSV(csvData);
  9. displayFamilyTree(member, indent)

    Displays the family tree starting from a specified member recursively.

    • Parameters:
      • member (FamilyMember): Optional. Starting member to display (default: root member).
      • indent (String): Optional. String for indentation (default: "").
    familyTree.displayFamilyTree(); // Displays the entire family tree starting from the root member
  10. toJson()

    Converts the family tree data to JSON format.

    • Returns:
      • JSON string representation of the family tree data.
    const jsonData = familyTree.toJson();
    console.log('Family tree JSON:', jsonData);

Class: FamilyMember

Represents a member of the family.

Constructor: new FamilyMember(data)

Initializes a new instance of FamilyMember with the provided data.

  • Parameters:
    • data (Object): Data object containing member details (id, name, gender, birthDate, deathDate, parents, children, siblings, spouse, phone).

Methods:

  • addChild(child): Adds a child to the member.
  • addSibling(sibling): Adds a sibling to the member.
  • addSpouse(spouse): Sets the spouse of the member.
  • addEvent(event): Adds a special event to the member.

Examples

// Initialize the family tree
import ADABsilsilah from 'adab-silsilah-tree';

const rootMemberData = {
  id: 1,
  name: 'John Doe',
  gender: 'male',
  birthDate: '1980-01-01',
  phone: '1234567890'
};

const familyTree = new ADABsilsilah(rootMemberData);

// Add members and relationships
const janeData = {
  id: 2,
  name: 'Jane Doe',
  gender: 'female',
  birthDate: '1985-03-15',
  phone: '9876543210'
};
familyTree.addMember(janeData, 'child', 1); // Jane Doe is a child of John Doe

// Update member information
const updatedInfo = {
  name: 'Jane Doe-Smith',
  phone: '9876543210'
};
familyTree.updateMember(2, updatedInfo); // Updates Jane Doe's name and phone number

// Display family tree
familyTree.displayFamilyTree(); // Displays the entire family tree

// Search members
const results = familyTree.searchMembers('Jane');
console.log('Search results:', results);

// Export to CSV
const csvData = familyTree.exportToCSV();
console.log('Exported CSV data:', csvData);

// Import from CSV
const csvImportData = `
  ID,Name,Gender,BirthDate,DeathDate,Parents,Children,Siblings,Spouse,Phone
  1,"John Doe",male,1980-01-01,,2,,,,1234567890
  2,"Jane Doe-Smith",female,1985-03-15,,,1,,1,9876543210
`;
familyTree.importFromCSV(csvImportData);

Notes

  • Ensure all data provided is valid according to the required format.
  • Handle exceptions and errors appropriately when using methods.

Dokumentasi di atas memberikan gambaran lengkap tentang penggunaan ADABsilsilah, termasuk cara menginisialisasi, menambahkan anggota, mengelola relasi, mencari anggota, mengimpor/ mengekspor data, dan banyak lagi. Pastikan untuk memahami dan mengadaptasi sesuai dengan kebutuhan proyek Anda.