1.0.22 ā€¢ Published 4 years ago

starwars_character_finder v1.0.22

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

A npm package to search Starwars characters based on certain attributes, such as gender, eye color and skin color

Data derived from www.swapi.co

Install

npm install starwars_character_finder

Repo Overview (FYI only)

  • data is obtained from www.swapi.co
  • loadCharInfo.js parses info from swapi.co and creates json files to be read
  • index.js - implements functions
  • test.js - test cases for the operations

Usage

To import:

const sw = require('starwars_character_finder')

To Search for character based on attributes, such as height, eye color, etc:

sw.searchCharacter(query).then(res=>(console.log(res))

where query is a JavaScript object in the following form:

let query = {"AND":[], "OR":[]}

// query will get items that match all items in AND and any one item in OR

and the AND or OR array can have any of the following object:

     {
          name: String,
          name_exact: Boolean
      },
      {
          height_lo: Integer,
          height_hi: Integer
      },
      {
          mass_lo: Integer,
          mass_hi: Integer
      },
      {hair_color: String},
      {skin_color: String},
      {eye_color: String},
      {gender: String}

sample data:

hair_colorskin_coloreye_color
nonenoneblue
n/agoldyellow
blondewhitered
brownbluebrown
greylightblue-gray
blackredblack
auburnunknownorange
whitegreenhazel
unknowngreen-tanpink
brownunknown
paleblue
metalgold
darkgreen
brown mottlewhite
greydark
yellow
silver
fair

height range : 66 - 264 cm

mass range: 15, 1358 kg

name_exact : true for exact search, false for partial match

To get complete details on above data as JSON,

sw.getParameterDetails().then(res=>(console.log(res)))

Complete example for searching:

let query = {
               "AND":[
                  {
                     "name":"Sky",
                     "name_exact":false
                  }
               ],
               "OR":[
                  {
                     "mass_lo":150,
                     "mass_hi":1900
                  },
                  {
                     "eye_color":"SOME INVALID ITEM"
                  },
                  {
                     "skin_color":"blue"
                  }
               ]
            }
sw.searchCharacter(query).then(res=>(console.log(res))) 

To add/remove characters

Add - If query has no "name" key or tries to add an existig character (eg, Luke Skywalker), then promise is rejected

let addQuery = {
   "name":"New Person",
   "eye_color":"blue"
}
sw.addNewEntry(addQuery).then(res=>(...)).catch(err=>(...))

Remove - Remove based on name

  sw.removeEntry('Luke Skywalker').then(res=>())

Run tests

npm run test

Author

šŸ‘¤ Henry Lee

Show your support

Give a ā­ļø if this project helped you!


This README was generated with ā¤ļø by readme-md-generator

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.11

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago