Skip to content

zackyjsd/kevast-gist.js

 
 

Repository files navigation

kevast-gist.js

Build Status Coverage Status Dependencies Dev Dependencies Package Version Open Issues MIT License

A gist storage for kevast.js.

Installation

Node.js

Using yarn

yarn add kevast-gist

Using npm

npm install kevast-gist

Browser

<script src="https://cdn.jsdelivr.net/npm/kevast-gist/dist/kevast-gist.min.js"></script>

Usage

Only access token given:

const { Kevast } = require('kevast');
const { KevastGist } = require('kevast-gist');
const assert = require('assert');

const ACCESS_TOKEN = 'YOUR GITHUB ACCESS TOKEN';

(async () => {
  const kevastGist = await KevastGist.create(ACCESS_TOKEN);
  // Gist id and filename will be generated automatically
  console.log(kevastGist.getGistId());
  console.log(kevastGist.getFilename());

  const kevast = new Kevast(kevastGist);
  await kevast.set('key', 'value');
  assert(await kevast.get('key') === 'value');
})();

Access token and gist id given:

const { Kevast } = require('kevast');
const { KevastGist } = require('kevast-gist');
const assert = require('assert');

const ACCESS_TOKEN = 'YOUR GITHUB ACCESS TOKEN';
const GIST_ID = 'GIST ID';

(async () => {
  const kevastGist = await KevastGist.create(ACCESS_TOKEN, GIST_ID);
  assert(kevastGist.getGistId() === GIST_ID);
  // Filename will be generated automatically
  console.log(kevastGist.getFilename());

  const kevast = new Kevast(kevastGist);
  await kevast.set('key', 'value');
  assert(await kevast.get('key') === 'value');
})();

Access token, gist id and filename given:

const { Kevast } = require('kevast');
const { KevastGist } = require('kevast-gist');
const assert = require('assert');

const ACCESS_TOKEN = 'YOUR GITHUB ACCESS TOKEN';
const GIST_ID = 'GIST ID';
const FILENAME = 'FILE NAME';

(async () => {
  const kevastGist = await KevastGist.create(ACCESS_TOKEN, GIST_ID, FILENAME);
  assert(kevastGist.getGistId() === GIST_ID);
  assert(kevastGist.getFilename() === FILENAME);

  const kevast = new Kevast(kevastGist);
  await kevast.set('key', 'value');
  assert(await kevast.get('key') === 'value');
})();

How to get a GitHub Access Token

Click this link to generate a new GAT.

Steps:

  1. Description

The description is arbitrary. You can fill in anything you like. But kevast-gist is recommended to remind you this GAT is being used by this kevast-gist.

  1. Scopes

Kevast-gist only requires Gist scope, so please do not check other unnecessary permissions to ensure your account security.

  1. Generate

Click Generate button and you will see the newly created GAT.

ATTENTION: You won't be able to see it again. Please keep it properly, otherwise it can only be regenerated.

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 89.8%
  • JavaScript 10.2%