open-index/open-npm huggingface dataset:
npm package: @hbauer/local-cache
Description: ## Install
Author: Donald Geddes
Latest version: 0.3.0

# @hbauer/local-cache

## Install

```sh
$ yarn add @hbauer/local-cache
$ npm install @hbauer/local-cache
```

## Usage

```js
import { LocalHTTPCache } from '@hbauer/local-cache'

const rootDirectory = '__cache' // writes to $PROJECT_ROOT/__cache/...
const name = 'movies' // writes to $PROJECT_ROOT/__cache/movies/...

const cache = new LocalHTTPCache('https://imdb.com', 'html', {
  rootDirectory,
  name,
})

const href = `${baseURL}/title/${movieId}` // i.e. https://imdb.com/title/...'
const data = await fetch(href).then(response => response.text())
const file = await cache.set(href, data)

assert.equal(file instanceof LocalFile === true)
assert.equal(file.filename, movieId)
assert.deepEqual(file.data, data)
assert.deepEqual(file.data, await cache.get(href))

const { filename, fullPath } = cache.getPaths(href)

assert.equal(file.filename, filename)
assert.equal(file.path.endsWith(fullPath) === true)

// TODO: finish readme
```
npm package: @hbauer/local-file
Description: ## Install
Author: Donald Geddes
Latest version: 0.5.0

# @hbauer/local-file

## Install

```sh
$ yarn add @hbauer/local-file
$ npm install @hbauer/local-file
```

## Usage

```js
import { LocalFile } from '@hbauer/local-file'

const path = 'src/path/to/data'
const data = { foo: 'bar' }

const savedFile = await LocalFile.save(path, data)

assert(savedFile.data === data)
assert(typeof savedFile.createdAt.date === 'date')
assert(typeof savedFile.createdAt.milliseconds === 'number')

const file = await LocalFile.read(path, data) // throws error if the file doesn't exist

assert.deepEqual(savedFile.data, file.data)

// TODO: finish readme
```
npm package: @hbauer/remote-diff
Description: ## Install
Author: Donald Geddes
Latest version: 0.3.0

# hbauer/remote-diff

## Install

```sh
$ yarn add @hbauer/remote-diff
$ npm install @hbauer/remote-diff
```

## Usage

```js
import { getRemoteDiff } from '@hbauer/remote-diff'

const href = 'http://asdf.com'
const selector = 'p' // all <p> elements
const opts = { basePath: '_data' } // where would you like data stored?

const changes = await getRemoteDiff(href, selector, opts)

assert(changes.directory === '_data')
assert(changes.filename === 'asdf-com')
assert(changes.existing === false) // has this resource been previously fetched?
assert(changes.changed === 0) // # of characters changed
assert(changes.added.length === 0) // `added` is an array of strings that have been added
assert(changes.removed.length === 0) // `removed` is an array of strings that have been removed
```
npm package: @hbauer/scrape
Description: ## Installation
Author: Donald Geddes
Latest version: 0.7.9

# @hbauer/scrape

## Installation

```sh
$ yarn add @hbauer/scrape
$ npm install @hbauer/scrape
```

## Usage

### Basic

```js
import { Scrape } from '@hbauer/scrape'

const baseURL = 'https://httpbin.org' // trailing slash is OK

const httpbin = await Scrape.init(baseURL, {
  contentType, // 'json' | 'html' (defaults to 'json')
  returnRawFetchResponse, // boolean (defaults to false)
  cache: {
    enabled, // boolean (defaults to true)
    rootDirectory, // string (defaults to '__cache')
    name, // can be anything, e.g. 'scraper-name' (defaults to the hostname of the baseURL)
    fileExtension, // can be anything, e.g. 'json' | 'html' (defaults to undefined)
  }
  retry: {
    attempts, // number (defaults to 0)
  }
  throttle: {
    interval, // number (in milliseconds; defaults to 1000)
    limit, // number (defaults to 1)
  }
})

// Scraping a resource is now as simple as:
const file = await httpbin.scrape('uuid')

// Using an absolute URL instead (this results in the the exact same behaviour):
const absolute = await httpbin.scrape('https://httpbin.org/uuid')

// Future calls to the same URL will return from the cache:
const cachedFile = await httpbin.scrape('uuid')

assert.equal(cachedFile.attributes.fromCache, true)

// You can force invalidate a file:
const forceInvalidated = await httpbin.scrape('uuid', { invalidate: { force: true } }) // always re-fetches

assert.equal(cachedFile.attributes.fromCache, false)

// Or invalidate based on how old the file is
const expired = await httpbin.scrape('uuid', { invalidate: { expiredAfter: [1, 'week'] } })

assert.equal(cachedFile.attributes.expired, true)
```

### Cache

```js
import { Scrape } from '@hbauer/scrape'

const baseURL = 'https://httpbin.org'

/**
 * Cache Options
 *
 * enabled - the cache can be enabled or disabled (enabled by default)
 * rootDirectory - PROJECT_ROOT/${rootDirectory}
 * name - alternatively, PROJECT_ROOT/${rootDirectory}/${name}
 * fileExtension - PROJECT_ROOT/${rootDirectory}/${name}/path/file.${fileExtension}
 */
const httpbin = Scrape.init(baseURL, { contentType: 'html' })

const file = await httpbin.scrape('html') // alias for https://httpbin.org/html

// Get the local path to a cached file:
const { fullPath } = await httpbin.cache.getPaths('html') // = '__cache/httpbin.org/html'

// Get the cached file
const cachedFile = await httpbin.cache.get('html')

assert.equal(file.data, cachedFile.data)
```
npm package: @hbauer/time-since-file
Description: ## Install
Author: Donald Geddes
Latest version: 0.2.0

# @hbauer/time-since-file

## Install

```bash
$ yarn add @hbauer/time-since-file
$ npm install @hbauer/time-since-file
```

## Usage

```js
import { timeSinceFile } from '@hbauer/time-since-file'

const path = 'path/to/file.ext' // e.g. file created 36 hours ago
const since = await timeSinceFile(path)

assert(since.created.milliseconds === 36 * 60 * 60 * 1000)
assert(since.created.seconds === 36 * 60 * 60)
assert(since.created.minutes === 36 * 60)
assert(since.created.hours === 36)
// etc.
```