JSPM

goggledy

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q29049F
  • License GPL-3.0-or-later

Library to parse and generate Goggles.

Package Exports

  • goggledy
  • goggledy/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (goggledy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


Goggledy

Goggledy is a TypeScript library that lets you easily interact with Brave Search Goggles.

It can be used to parse Goggle code into a JavaScript representation, or to generate goggle code from a Goggle object.

This opens the door for applications that want to interact with Goggles in a more programmatic way. E.g. interactive editors, code generators, etc.

Parsing Goggles

Parsing a goggle into a structured JavaScript representation holding all the information about the Goggle with Goggle.parse():

import { Goggle } from 'goggledy'

const goggle = Goggle.parse(
  `! name: Some name
   ! description: Some description`,
)

console.log(goggle.metaData.name) // Some name

Generating Goggles

Generating Goggles from JavaScript representation with Goggle.toString():

import * as goggledy from 'goggledy'

const goggle = new goggledy.Goggle(
  // Goggle lines, e.g. instructions, comments, etc.
  [
    new goggledy.GoggleEmpty(),
    new goggledy.GoggleComment('Some comment'),
    new goggledy.GoggleInstruction('pattern', {
      site: 'example.org',
      discard: true,
    }),
  ],
  // Goggle meta data
  {
    name: 'Some name',
    description: 'Some description',
    // This is a shorthand for:
    // `goggledy.GoggleMeta('name', 'Some name')`
    // under the lines array above.
  },
)

console.log(goggle.toString())
// ! name: Some name
// ...

Comparison

See how to construct a Goggle in Goggledy and what values it returns with its toString() method, and when it is passed to JSON.stringify().

Goggle Goggledy JSON
! name: Some name
! description: Some description
! public: true
new Goggle([], {
  name: 'Some name',
  description: 'Some description',
  public: true,
})
{
  "metaData": {
    "name": "Some name",
    "description": "Some description",
    "public": true
  },
  "lines": [
    {
      "type": "meta",
      "key": "name",
      "value": "Some name"
    },
    {
      "type": "meta",
      "key": "description",
      "value": "Some description"
    },
    {
      "type": "meta",
      "key": "public",
      "value": true
    }
  ]
}
pattern$boost=10,incontent,site=example.org
new GoggleInstruction('pattern', {
  boost: 10,
  incontent: true,
  site: 'example.org',
})
{
  "type": "instruction",
  "pattern": "pattern",
  "options": {
    "boost": 10,
    "incontent": true,
    "site": "example.org"
  }
}
! name: value
new GoggleMeta('name', 'value')
{
  "type": "meta",
  "key": "name",
  "value": "value"
}
! comment
new GoggleComment(' comment')
{
  "type": "comment",
  "value": " comment"
}
new GoggleEmpty()
{
  "type": "empty"
}

Who uses Goggledy?

  • Gearchy uses Goggledy for two matters, parsing Goggles stored in GitHub gists to populate its interactive Goggle editor, and generating Goggles from the editor to store them back in GitHub gists.