cactus-stack
- A library for cactus stack works on Node.js
npm i cactus-stack --save
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)