Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snap-shot-core

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snap-shot-core - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

10

package.json
{
"name": "snap-shot-core",
"description": "Save / load named snapshots, useful for tests",
"version": "1.1.0",
"version": "1.2.0",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",

@@ -61,2 +61,5 @@ "bugs": "https://github.com/bahmutov/snap-shot-core/issues",

},
"release": {
"analyzeCommits": "simple-commit-message"
},
"devDependencies": {

@@ -71,4 +74,5 @@ "ban-sensitive-files": "1.9.0",

"pre-git": "3.13.0",
"standard": "8.6.0",
"semantic-release": "^6.3.2"
"semantic-release": "^6.3.2",
"simple-commit-message": "3.0.1",
"standard": "8.6.0"
},

@@ -75,0 +79,0 @@ "dependencies": {

@@ -25,3 +25,4 @@ # snap-shot-core

file: __filename,
specName: 'my test', // or whatever name you want to give
specName: 'my test', // or whatever name you want to give,
store, // optional function to preprocess the value before storing
compare: compareFn,

@@ -32,2 +33,27 @@ ext: '.test' // default value is '.snapshot'

## Store function
Sometimes you want to store not the value itself, but something derived,
like the object's schema (check out [schema-shot][schema-shot]). You can
pass a function `store` that transforms the object before saving.
For example if we are only interested in the type of value, we can do the
following (paired with the right `compare` function).
```js
const store = x => typeof x
// expected - previously saved "type of" value
// value - current original value
const compare = ({expected, value}) => ({
valid: typeof value === expected,
message: 'check the type'
})
snapShot({
what,
store,
compare
})
```
## Compare function
The comparator function needs to compare two values and return an object.

@@ -52,2 +78,7 @@ Here is an example

## Returned value
The `snapShotCore` function returns the *expected* value.
If this is the first time, it will be `store(what)` value. Otherwise it will be the loaded `expected` value.
[snap-shot]: https://github.com/bahmutov/snap-shot

@@ -54,0 +85,0 @@ [schema-shot]: https://github.com/bahmutov/schema-shot

@@ -14,2 +14,4 @@ 'use strict'

const identity = x => x
// TODO do we still need this? Is this working?

@@ -82,2 +84,3 @@ let fs

specName,
store = identity,
compare,

@@ -90,2 +93,3 @@ ext = '.snapshot',

la(is.fn(compare), 'missing compare function', compare)
la(is.fn(store), 'invalid store function', store)

@@ -112,4 +116,12 @@ if (ext) {

if (expected === undefined) {
storeValue({file, specName, index, value, ext, opts})
return value
const storedValue = store(value)
storeValue({
file,
specName,
index,
value: storedValue,
ext,
opts
})
return storedValue
}

@@ -124,3 +136,3 @@

})
return value
return expected
}

@@ -127,0 +139,0 @@

@@ -20,2 +20,5 @@ 'use strict'

function strip (o) {
if (is.fn(o)) {
return o
}
return JSON.parse(JSON.stringify(o))

@@ -22,0 +25,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc