New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@randlabs/js-config-reader

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@randlabs/js-config-reader - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

4

dist/index.d.ts
import Ajv from "ajv";
type DefaultSettings = Record<string, unknown>;
type LoaderCallback<S> = (source: string) => Promise<S>;
type LoaderCallback = (source: string) => Promise<string>;
type ExtendedValidatorCallback<S> = (settings: S) => Promise<void> | void;

@@ -9,3 +9,3 @@ interface Options<S> {

cmdLineParam?: string;
loader?: LoaderCallback<S>;
loader?: LoaderCallback;
schema?: string | Record<string, unknown>;

@@ -12,0 +12,0 @@ schemaOpts?: Ajv.Options;

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("ajv"),r=require("ajv-formats-draft2019"),t=require("fs"),o=require("json5"),s=require("path");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(e),i=a(r),c=a(t),l=a(o),f=a(s);class d extends Error{constructor(e){super(e),this.name="ValidationError",this.failures=[],Object.setPrototypeOf(this,new.target.prototype)}}let u,p;exports.ValidationError=d,exports.get=function(){return u},exports.getSource=function(){return p},exports.initialize=async function(e){let r;if(void 0!==e){if("object"!=typeof e||Array.isArray(e))throw new Error("Options not set")}else e={};if("string"==typeof e.source&&(r=e.source),r||"string"!=typeof e.envVar||"string"==typeof process.env[e.envVar]&&(r=process.env[e.envVar]),!r){let t="settings";"string"==typeof e.cmdLineParam&&e.cmdLineParam.length>0&&(t=e.cmdLineParam),t="--"+t;for(let e=0;e<process.argv.length;e++)if(process.argv[e]===t){if(e+1>=process.argv.length)throw new Error("Missing source in '"+t+"' parameter.");r=process.argv[e+1];break}}if(!r)throw new Error("Source not defined");if(e.loader)u=await e.loader(r);else try{if(r=f.default.resolve(process.cwd(),r),r.endsWith(".js"))u=require(r);else{const e=c.default.readFileSync(r);u=l.default.parse(e.toString())}}catch(e){throw new Error("Unable to load configuration.")}if(e.schema){let r;if("string"==typeof e.schema)try{const t=f.default.resolve(process.cwd(),e.schema),o=c.default.readFileSync(t);r=l.default.parse(o.toString())}catch(e){throw new Error("Unable to load schema.")}else{if("object"!=typeof e.schema)throw new Error("Invalid validator schema.");r=e.schema}const t="object"==typeof e.schemaOpts?e.schemaOpts:{},o=new n.default({...t,allErrors:!0,messages:!0,useDefaults:!0,format:"full"});i.default(o);const s=o.compile(r);if(!s(u)){const e=new d("Validation failed.");if(s.errors)for(const r of s.errors)e.failures.push({location:r.schemaPath,message:r.message||""});throw e}}return p=r,e.extendedValidator&&await e.extendedValidator(u),u};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("ajv"),r=require("ajv-formats-draft2019"),t=require("fs"),o=require("json5"),s=require("path");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(e),i=a(r),c=a(t),l=a(o),f=a(s);class d extends Error{constructor(e){super(e),this.name="ValidationError",this.failures=[],Object.setPrototypeOf(this,new.target.prototype)}}let u,p;exports.ValidationError=d,exports.get=function(){return u},exports.getSource=function(){return p},exports.initialize=async function(e){let r;if(void 0!==e){if("object"!=typeof e||Array.isArray(e))throw new Error("Options not set")}else e={};if("string"==typeof e.source&&(r=e.source),r||"string"!=typeof e.envVar||"string"==typeof process.env[e.envVar]&&(r=process.env[e.envVar]),!r){let t="settings";"string"==typeof e.cmdLineParam&&e.cmdLineParam.length>0&&(t=e.cmdLineParam),t="--"+t;for(let e=0;e<process.argv.length;e++)if(process.argv[e]===t){if(e+1>=process.argv.length)throw new Error("Missing source in '"+t+"' parameter.");r=process.argv[e+1];break}}if(!r)throw new Error("Source not defined");try{if(e.loader){const t=await e.loader(r);u=l.default.parse(t)}else if(r=f.default.resolve(process.cwd(),r),r.endsWith(".js"))u=require(r);else{const e=c.default.readFileSync(r);u=l.default.parse(e.toString())}}catch(e){throw new Error("Unable to load configuration ["+e.message+"].")}if(e.schema){let r;if("string"==typeof e.schema)try{const t=f.default.resolve(process.cwd(),e.schema),o=c.default.readFileSync(t);r=l.default.parse(o.toString())}catch(e){throw new Error("Unable to load schema.")}else{if("object"!=typeof e.schema)throw new Error("Invalid validator schema.");r=e.schema}const t="object"==typeof e.schemaOpts?e.schemaOpts:{},o=new n.default({...t,allErrors:!0,messages:!0,useDefaults:!0,format:"full"});i.default(o);const s=o.compile(r);if(!s(u)){const e=new d("Validation failed.");if(s.errors)for(const r of s.errors)e.failures.push({location:r.schemaPath,message:r.message||""});throw e}}return p=r,e.extendedValidator&&await e.extendedValidator(u),u};
//# sourceMappingURL=index.js.map
{
"name": "@randlabs/js-config-reader",
"version": "1.0.2",
"version": "1.0.3",
"description": "Configuration settings loader",

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

@@ -8,3 +8,3 @@ # js-config-reader

```shell
npm install --save @randlabs/config-reader
npm install --save @randlabs/js-config-reader
```

@@ -15,3 +15,3 @@

```javascript
const ConfigReader = require("@randlabs/config-reader");
const ConfigReader = require("@randlabs/js-config-reader");

@@ -23,3 +23,3 @@ const settings = await ConfigReader.initialize(options);

```javascript
const ConfigReader = require("@randlabs/config-reader");
const ConfigReader = require("@randlabs/js-config-reader");

@@ -34,3 +34,3 @@ const settings = await ConfigReader.initialize({

* `source` - Source location of the configuration settings. Can be a filename or url depending on the used loader.
* `source` - Source location of the configuration settings. Can be a filename or url depending on the used loader. Optional.
* `envVar` - Environment variable name used to find the source. Optional.

@@ -37,0 +37,0 @@ I.e.: Define `export MY_SETTINGS=/home/myuser/settings.json` and set `MY_SETTINGS` as the `envVar`.

@@ -11,3 +11,3 @@ import Ajv from "ajv";

export type LoaderCallback<S> = (source: string) => Promise<S>;
export type LoaderCallback = (source: string) => Promise<string>;

@@ -20,3 +20,3 @@ export type ExtendedValidatorCallback<S> = (settings: S) => Promise<void> | void;

cmdLineParam?: string;
loader?: LoaderCallback<S>;
loader?: LoaderCallback;
schema?: string | Record<string, unknown>;

@@ -118,4 +118,4 @@ schemaOpts?: Ajv.Options;

// check for loader, if none provided, read from disk file
if (!options.loader) {
try {
try {
if (!options.loader) {
source = path.resolve(process.cwd(), source);

@@ -133,8 +133,9 @@

}
catch (err) {
throw new Error("Unable to load configuration.");
else {
const contents = await options.loader(source);
settings = JSON5.parse(contents);
}
}
else {
settings = await options.loader(source);
catch (err) {
throw new Error("Unable to load configuration [" + err.message + "].");
}

@@ -141,0 +142,0 @@

Sorry, the diff of this file is not supported yet

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