0.4.0 • Published 1 year ago

@mateonunez/lyra-impact v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

🌍☄️️ Impact

Create a Lyra database from anywhere.

Tests

Installation

You can install Lyra using npm, yarn, pnpm:

npm i @mateonunez/lyra-impact
yarn add @mateonunez/lyra-impact
pnpm add @mateonunez/lyra-impact

Examples

See the full list of examples: mateonunez/lyra-impact-examples

Usage

import { search } from "@lyrasearch/lyra"
import { impact } from "@mateonunez/lyra-impact"

(async () => {
  const lyra = await impact("https://raw.githubusercontent.com/LyraSearch/lyra/main/examples/with-vue/public/pokedex.json")

  const { hits } = await search(lyra, { term: "pikachu" })

  console.log(hits)
})();

Result

[
  {
    num: '025',
    name: 'Pikachu',
    img: 'http://www.serebii.net/pokemongo/pokemon/025.png',
    type: [ 'Electric' ],
    height: '0.41 m',
    weight: '6.0 kg',
    candy: 'Pikachu Candy',
    candy_count: 50,
    egg: '2 km',
    spawn_chance: 0.21,
    avg_spawns: 21,
    spawn_time: '04:00',
    multipliers: [ 2.34 ],
    weaknesses: [ 'Ground' ],
    next_evolution: [ { num: '026', name: 'Raichu' } ]
  }
];

Formats and fetchers

lyra-impact supports the following formats and fetchers:

FormatFetcherDescription
JSONfetch, filesystemFetches a JSON response or file
GraphQLgraphqlFetches a GraphQL endpoint
CSVfetch, filesystemFetches a CSV file from a URL or filesystem
XML (REMOVED)fetch, filesystemFetches a XML file from a URL or filesystem

With GraphQL

import { search } from "@lyrasearch/lyra"
import { impact } from "@mateonunez/lyra-impact"

(async () => {
  const lyra = await impact("https://rickandmortyapi.com/graphql", {
    fetch: {
      fetcher: "graphql",
      query: `{
        characters {
          results {
            type
            status
            species
            name
            id
            gender
          }
        }
      }`,
      property: "characters.results"
    }
  })

  const { hits } = await search(lyra, {
    term: "Morty"
  })

  console.log(hits)
})()

With Filesystem

import { search } from "@lyrasearch/lyra"
import { impact } from "@mateonunez/lyra-impact"

(async () => {
  const lyra = await impact("./data/examples/characters.csv", {
    fetch: {
      fetcher: "filesystem"
    }
  })

  const { hits } = await search(lyra, {
    term: "Morty"
  })

  console.log(hits)
})()

Collision

collision method allows you to fetch and search a term in the API results.

  • url: string
  • searchOptions: SearchOptions
  • impactOptions: ImpactOptions
import { collision } from "@mateonunez/lyra-impact"

(async () => {
  const { hits } = await collision("https://raw.githubusercontent.com/LyraSearch/lyra/main/examples/with-vue/public/pokedex.json", { 
    term: "pikachu" 
  })

  console.log(hits)
})();

Result

[
  {
    num: '025',
    name: 'Pikachu',
    img: 'http://www.serebii.net/pokemongo/pokemon/025.png',
    type: [ 'Electric' ],
    height: '0.41 m',
    weight: '6.0 kg',
    candy: 'Pikachu Candy',
    candy_count: 50,
    egg: '2 km',
    spawn_chance: 0.21,
    avg_spawns: 21,
    spawn_time: '04:00',
    multipliers: [ 2.34 ],
    weaknesses: [ 'Ground' ],
    next_evolution: [ { num: '026', name: 'Raichu' } ]
  }
];

License

MIT

0.4.0

1 year ago

0.3.6

1 year ago

0.3.8

1 year ago

0.3.0

2 years ago

0.3.5

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.1-beta.8

2 years ago

0.0.1-beta.7

2 years ago

0.0.1-beta.6

2 years ago

0.0.1-beta.5

2 years ago

0.0.1-beta.4

2 years ago

0.0.1-beta.3

2 years ago

0.0.1-beta.2

2 years ago

0.0.1-beta.1

2 years ago

0.0.1-beta.0

2 years ago

0.0.0-alpha.1

2 years ago

0.0.0-alpha.0

2 years ago