Skip to content

Migration from bury (v1)

This guide helps you transition from the legacy bury (v1) package to bury2.


Why bury2?

bury (v1) was designed around modifying global prototypes (e.g. Array.prototype.uniq = ...). While convenient in small demo scripts, prototype pollution carries significant risks:

  • Conflicts with other libraries or future JavaScript specifications.
  • Hard-to-trace bugs across large codebases.
  • Incompatibility with strict enterprise environments and security audits.

bury2 completely reimagines the library with a pure wrapper design, zero prototype pollution, and full TypeScript type inference.


Summary of Changes

Featurebury (v1)bury2
Entry PointAuto-applied upon import 'bury'Explicit wrapper: bury(value)
Global Prototype Pollution⚠️ Yes (Array.prototype, etc.)Zero pollution
UnwrappingDirect native return.value or .unwrap()
ImmutabilityMixed (some methods mutated inplace)100% Guaranteed Immutable
TypeScript SupportPartial / ambient type declarationsPrecise end-to-end generics
Callable GettersNot available.prop and .prop() both work

Migration Examples

Array Transformation

typescript
import 'bury';

// Native array modified via prototype extension
const numbers = [1, 2, 2, 3, null];
const result = numbers.compact().uniq();
typescript
import { bury } from 'bury2';

const numbers = [1, 2, 2, 3, null];
// Wrap with bury() and unwrap with .value
const result = bury(numbers)
  .compact
  .uniq
  .value;

String Operations

typescript
import 'bury';

const str = '  hello world  ';
const upper = str.upcase().trim();
typescript
import { bury } from 'bury2';

const str = '  hello world  ';
const upper = bury(str)
  .upcase
  .trim
  .value;

Migration Checklist

  1. Replace import 'bury' with import { bury } from 'bury2'.
  2. Wrap targets at the start of method chains: bury(target).
  3. Add .value or .unwrap() at the end of the chain to retrieve raw primitives or arrays.
  4. Remove any global prototype declaration augmentations (global.d.ts) that were used for v1.

Released under the MIT License.