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

simple-save

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-save - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

14

index.js
var fs = require("fs");
delete require.cache[__filename];
var escapeRegex = function(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
module.exports = function (pattern) {
var PATTERN = pattern || "SS";
return function(name, value) {
return function(name, value, suffix) {
//console.log("Changing "+name+" to `" + value + "`");
name = escapeRegex(name);
suffix = escapeRegex(suffix);
fs.readFile(module.parent.filename, "utf-8", function(err, data) {
if(err) throw err;
var match = "(\\/\\*"+PATTERN+"\\*\\/.*?"+name+".*?=).*;";
var match = "(\\/\\*" + PATTERN +
(suffix ? ":" + suffix : "") +
"\\*\\/.*?" + name + ".*?=).*;";
var replace = '$1 '+JSON.stringify(value)+";";

@@ -20,1 +27,2 @@ data = data.replace(RegExp(match, "gm"), replace);

};
{
"name": "simple-save",
"version": "1.0.0",
"version": "1.0.1",
"description": "A stupidly simple way to persist data.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,3 +11,12 @@ # simple-save

# Usage
```js
save(variableName:string, newValue, [suffix:string])
```
Call the package with the name of the variable you want to persist, and the new
value. This will replace the assignments of all tagged occurrences of this
variable with the new value.
```js
var save = require("simple-save")();

@@ -20,2 +29,5 @@ /*SS*/ var test = 3;

# Advanced
If you want to set a custom tag instead of the default of `"SS"`, pass in a

@@ -26,1 +38,15 @@ string:

```
You can also set custom tag suffixes on a per-variable basis as follows. In the
following example, only the value of the variable within the function is modified.
```js
var save = require("simple-save")();
/*SS*/ var test = 3;
function ttt(){
/*SS:1*/ var test = 3;
}
test = 5
save("test", test, "1");
```
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