New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

swapi-ts

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swapi-ts

a ts wrapper for swapi.dev

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
-62.5%
Maintainers
1
Weekly downloads
 
Created
Source

swapi-ts

Table of Contents

  • About
  • Getting Started
  • Usage
  • Contributing

About

This is a wrapper for the swapi.dev website

Getting Started

There are few collection that can hold (Resources)

SWApi.Films
SWApi.People
SWApi.Planets
SWApi.Species
SWApi.Starships
SWApi.Vehicles

you can query by find(predicate) which goes through all the pages and filter or use findBySearch([search_term]) which use the search url query

  SWApi.Planets.findBySearch(['Tatooine'])

every collection have resources which are of the Resources class and they have a value which contains the data queried from the server

you can also use the populateAll(path) method which replace the string \ string[] with the related object

all the information is cached in the local storage

Installing

npm i swapi-ts

Usage

    SWApi.Planets.findBySearch(['Tatooine', 'Alderaan', 'Naboo', 'Bespin', 'Endor'])
      .then(planets => _.map(planets.resources, planet => ({text: planet.value.name, value: parseInt(planet.value.population)})))

    SWApi.Vehicles.find(vehicle => vehicle.pilots.length > 0)
      .then(vehicles => vehicles.populateAll('pilots'))
      .then(vehicles => vehicles.populateAll('pilots.homeworld'))
      .then(vehicles => _.filter(vehicles.resources, vehicle => _.every(vehicle.value.pilots, (pilot => _.get(pilot, 'homeworld.population') !== 'unknown'))))
      .then(vehicles => _.map(vehicles, vehicle => ({
        name: vehicle.value.name,
        pilots: _.map(vehicle.value.pilots as SWApi.IPeople[], 'name'),
        population: _.map(vehicle.value.pilots, (pilot => ({name: _.get(pilot, 'homeworld.name'), population: _.get(pilot, 'homeworld.population')}))),
        get populationSum() {
          return _.sumBy(this.population, p => parseInt(p.population))
        }
      })))
      .then(vehicles => _.reverse(_.sortBy(vehicles, vehicle => vehicle.populationSum)))

Keywords

swapi

FAQs

Package last updated on 13 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts