Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

goggledy

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

goggledy

Library to parse and generate Goggles.

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source


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().

GoggleGoggledyJSON
! 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.

Keywords

goggles

FAQs

Package last updated on 24 Sep 2022

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