adab-silsilah-tree v1.0.0
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-treeUsage
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 containingid,name,gender,birthDate, and optionallyphone.
Methods:
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- Parameters:
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- Parameters:
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- Parameters:
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- Parameters:
findMember(memberId)Finds a member in the family tree based on their ID.
Parameters:
memberId(Number): ID of the member to find.
Returns:
FamilyMemberobject ornullif not found.
const member = familyTree.findMember(2); if (member) { console.log(`Found member: ${member.name}`); } else { console.log('Member not found'); }searchMembers(query)Searches for members in the family tree based on a query (name or gender).
Parameters:
query(String): Search query.
Returns:
- Array of
FamilyMemberobjects that match the query.
- Array of
const results = familyTree.searchMembers('Jane'); console.log('Search results:', results);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);- Returns:
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);- Parameters:
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- Parameters:
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);- Returns:
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.
2 years ago