1.0.2 • Published 2 years ago

cactus-stack v1.0.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
2 years ago

cactus-stack.js license npm

coverage dependency maintenance quality github travis

cactus-stack - A library for cactus stack works on Node.js

Installation

npm i cactus-stack --save

Usage

import { CactusStack, CactusStackError } from 'cactus-stack'

type Foo = {
  id: number
  name: string
}

const root = new CactusStack<Foo>()

const firstNode = root.push({
  id: 1,
  name: 'foo',
})

const secondNode = root.push({
  id: 2,
  name: 'bar',
})

const thirdNode = secondNode.push({
  id: 3,
  name: 'baz',
})

const baz = thirdNode.pop()
if (baz instanceof CactusStackError) {
  console.error(baz.message)
  process.exit(1)
}
console.assert(baz.id === 3)
console.assert(baz.name === 'baz')

const foo = firstNode.pop()
if (foo instanceof CactusStackError) {
  console.error(foo.message)
  process.exit(1)
}
console.assert(foo.id === 1)
console.assert(foo.name === 'foo')

const err = thirdNode.pop()
console.assert(err instanceof CactusStackError)