@strategies/versions
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

Sasaki's Versions

System for applying incremental patches to a data structure.

Install

yarn add @strategies/versions

Example

Create your version patches

const versions = new Versions({

	'1.0.0': file => {
		// perform work on file. Mutating file itsself is okay since we always
		// pass a fresh object into subsequent patches. 
		return file;
	},

	'2.0.0': file => {
		// ...
		return file;
	},

	// Patches can be declared out of order; that's okay. 
	'1.5.0': file => {
		// ...
		return file;
	},

});

console.log(versions.latest)   // -> '2.0.0'
console.log(versions.versions) // -> ['1.0.0', '1.5.0', '2.0.0']

Pass an object through

If the object does not contain a version key, then the data starts at 0.0.0.

const fileWithLatestPatch = versions.upgrade(file);
// fileWithLatestPatch.version === '2.0.0'

If you don't want to apply patches to the latest version, you can optionally specify which version as a second argument.

const fileAt1point5 = versions.upgrade(file, '1.5.0');

Readme

Keywords

none

Package Sidebar

Install

npm i @strategies/versions

Weekly Downloads

1

Version

1.1.5

License

MIT

Unpacked Size

41.7 kB

Total Files

7

Last publish

Collaborators

  • scottdpenman
  • tadiraman
  • sasaki-dev
  • arminakvn
  • eyoungberg
  • sasaki-strategies