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

@batuhanw/haf

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@batuhanw/haf - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

2

dist/get-config-path.d.ts

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

export declare const getConfigPath: (name: string, extension?: string | undefined) => string;
export declare const getConfigPath: (name: string, extension?: string) => string;

@@ -16,3 +16,3 @@ import type { FlattenedWithDotNotation, OptionalKeysOf, StringKeysOf, ArrayKeysOf } from './types';

set<Path extends StringKeysOf<FlattenedSchema>>(path: Path, value: FlattenedSchema[Path]): void;
append<Path extends ArrayKeysOf<FlattenedSchema>>(path: Path, ...values: FlattenedSchema[Path]): void;
append<Path extends ArrayKeysOf<FlattenedSchema>, Values extends Extract<FlattenedSchema[Path], unknown[]>>(path: Path, ...values: Values): void;
delete(path: OptionalKeysOf<FlattenedSchema>): void;

@@ -19,0 +19,0 @@ reset(path?: StringKeysOf<FlattenedSchema>): void;

"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _options, _defaultOptions;
var _Haf_options, _Haf_defaultOptions;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -21,4 +19,4 @@ const fs_extra_1 = require("fs-extra");

constructor(options) {
_options.set(this, void 0);
_defaultOptions.set(this, {
_Haf_options.set(this, void 0);
_Haf_defaultOptions.set(this, {
name: 'haf',

@@ -28,16 +26,16 @@ extension: '',

});
__classPrivateFieldSet(this, _options, Object.assign(__classPrivateFieldGet(this, _defaultOptions), options));
this.configPath = get_config_path_1.getConfigPath(__classPrivateFieldGet(this, _options).name, __classPrivateFieldGet(this, _options).extension);
__classPrivateFieldSet(this, _Haf_options, Object.assign(__classPrivateFieldGet(this, _Haf_defaultOptions, "f"), options), "f");
this.configPath = (0, get_config_path_1.getConfigPath)(__classPrivateFieldGet(this, _Haf_options, "f").name, __classPrivateFieldGet(this, _Haf_options, "f").extension);
this.upsertSchema();
}
upsertSchema() {
if (fs_extra_1.pathExistsSync(this.configPath))
if ((0, fs_extra_1.pathExistsSync)(this.configPath))
return;
fs_extra_1.writeJsonSync(this.configPath, __classPrivateFieldGet(this, _options).defaultSchema);
(0, fs_extra_1.writeJsonSync)(this.configPath, __classPrivateFieldGet(this, _Haf_options, "f").defaultSchema);
}
get store() {
return fs_extra_1.readJsonSync(this.configPath);
return (0, fs_extra_1.readJsonSync)(this.configPath);
}
set store(schema) {
fs_extra_1.writeJsonSync(this.configPath, schema);
(0, fs_extra_1.writeJsonSync)(this.configPath, schema);
}

@@ -52,4 +50,4 @@ get(path) {

const existingValues = this._get(path);
const result = [...existingValues, ...values];
this._set(path, result);
existingValues.push(...values);
this._set(path, existingValues);
}

@@ -61,14 +59,13 @@ delete(path) {

if (typeof path === 'undefined') {
this.store = __classPrivateFieldGet(this, _defaultOptions).defaultSchema || {};
this.store = __classPrivateFieldGet(this, _Haf_defaultOptions, "f").defaultSchema || {};
return;
}
const defaultValue = this._get(path, __classPrivateFieldGet(this, _defaultOptions).defaultSchema);
const defaultValue = this._get(path, __classPrivateFieldGet(this, _Haf_defaultOptions, "f").defaultSchema);
this._set(path, defaultValue);
}
nuke() {
fs_extra_1.removeSync(this.configPath);
(0, fs_extra_1.removeSync)(this.configPath);
}
_get(path, source) {
const keys = path.split('.');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let result = source ? source : this.store;

@@ -85,7 +82,5 @@ for (let i = 0; i < keys.length; i++) {

if (keys.findIndex((k) => k === key) === keys.length - 1) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
obj[key] = value;
}
else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return obj[key];

@@ -97,3 +92,3 @@ }

}
_options = new WeakMap(), _defaultOptions = new WeakMap();
_Haf_options = new WeakMap(), _Haf_defaultOptions = new WeakMap();
exports.default = Haf;

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

declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
/**

@@ -8,4 +8,4 @@ * Returns the intersection of all values of the object T. Example:

*/
declare type IntersectValuesOf<T> = UnionToIntersection<T[keyof T]>;
declare type AddPrefix<TKey extends string, Prefix> = Prefix extends string ? `${Prefix}.${TKey}` : TKey;
type IntersectValuesOf<T> = UnionToIntersection<T[keyof T]>;
type AddPrefix<TKey extends string, Prefix> = Prefix extends string ? `${Prefix}.${TKey}` : TKey;
/**

@@ -17,15 +17,14 @@ * Flattens an object type to a single object with dot notation for keys. Example:

*/
export declare type FlattenedWithDotNotation<Schema, Prefix = null> = {
export type FlattenedWithDotNotation<Schema, Prefix = null> = {
[K in string & keyof Schema as AddPrefix<K, Prefix>]: Schema[K];
} & // see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#key-remapping-in-mapped-types
IntersectValuesOf<{
} & IntersectValuesOf<{
[K in string & keyof Schema as AddPrefix<K, Prefix>]: Schema[K] extends Array<any> ? never : Schema[K] extends object ? FlattenedWithDotNotation<Schema[K], AddPrefix<K, Prefix>> : never;
}>;
declare type PrimitiveTypes = string | number | boolean | any[] | Record<string, unknown>;
export declare type StringKeysOf<Schema> = keyof Schema & string;
declare type ExtractKeysIn<Schema, Type> = keyof Pick<Schema, {
type PrimitiveTypes = string | number | boolean | any[] | Record<string, unknown>;
export type StringKeysOf<Schema> = keyof Schema & string;
type ExtractKeysIn<Schema, Type> = keyof Pick<Schema, {
[K in keyof Schema]: Schema[K] extends Type ? K : never;
}[keyof Schema]>;
export declare type OptionalKeysOf<Schema> = Exclude<StringKeysOf<Schema>, ExtractKeysIn<Schema, PrimitiveTypes>>;
export declare type ArrayKeysOf<Schema> = Extract<StringKeysOf<Schema>, ExtractKeysIn<Schema, any[]>>;
export type OptionalKeysOf<Schema> = Exclude<StringKeysOf<Schema>, ExtractKeysIn<Schema, PrimitiveTypes>>;
export type ArrayKeysOf<Schema> = StringKeysOf<Schema> & ExtractKeysIn<Schema, any[]>;
export {};
{
"name": "@batuhanw/haf",
"version": "0.1.3",
"version": "0.2.0",
"engines": {
"node": ">=10"
"node": ">=16"
},

@@ -19,2 +19,3 @@ "description": "Fully typed, modern, cross-platform persistent config solution for NodeJS projects",

"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write .",
"prepare": "npm run build",

@@ -44,18 +45,18 @@ "prepublishOnly": "npm test && npm run lint"

"devDependencies": {
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.22",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"eslint": "^7.18.0",
"eslint-plugin-expect-type": "0.0.5",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typescript": "^4.2.0-beta"
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.11",
"@types/node": "^18.19.3",
"@types/rimraf": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"eslint": "^8.56.0",
"eslint-plugin-expect-type": "^0.3.0",
"jest": "^29.7.0",
"prettier": "^3.1.1",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3"
},
"dependencies": {
"fs-extra": "^9.1.0",
"rimraf": "^3.0.2"
"fs-extra": "^11.2.0",
"rimraf": "^5.0.5"
},

@@ -62,0 +63,0 @@ "keywords": [

# 🧠 🔒 Haf 🦺 ✏️
[![npm version](https://img.shields.io/npm/v/@batuhanw/haf.svg)](https://www.npmjs.com/package/@batuhanw/haf)
![CI](https://github.com/BatuhanW/haf/workflows/main/badge.svg)
[![Known Vulnerabilities](https://snyk.io/test/github/BatuhanW/haf/badge.svg?targetFile=package.json)](https://snyk.io/test/github/BatuhanW/haf?targetFile=package.json)
[![Maintainability](https://api.codeclimate.com/v1/badges/4315aa36678fe4181b77/maintainability)](https://codeclimate.com/github/BatuhanW/haf/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/4315aa36678fe4181b77/test_coverage)](https://codeclimate.com/github/BatuhanW/haf/test_coverage)
[![Dependencies](https://status.david-dm.org/gh/batuhanw/haf.svg)](https://status.david-dm.org/gh/batuhanw/haf)
[![Dev Dependencies](https://status.david-dm.org/gh/batuhanw/haf.svg?type=dev)](https://status.david-dm.org/gh/batuhanw/haf)

@@ -53,28 +53,26 @@ Haf is a fully typed 🔒, cross-platform, persistent 💾 config ⚙️ solution for your NodeJS projects with a great developer experience!

```typescript
import Haf from '@batuhanw/haf'
import Haf from '@batuhanw/haf';
const haf = new Haf<DogSchema>(
{
name: 'myDog',
defaultSchema: {
name: 'Pop',
age: 2,
toys: ['socks', 'toilet paper'],
vaccines: [
{ name: 'rabbies', date: '2020-01-01' },
{ name: 'parasite', date: '2020-01-01', next: '2020-01-03' },
],
appearance: {
eyeColor: 'brown',
hairColor: {
primary: 'white',
secondary: undefined,
otherColors: ['black'],
},
const haf = new Haf<DogSchema>({
name: 'myDog',
defaultSchema: {
name: 'Pop',
age: 2,
toys: ['socks', 'toilet paper'],
vaccines: [
{ name: 'rabbies', date: '2020-01-01' },
{ name: 'parasite', date: '2020-01-01', nextDate: '2020-01-03' },
],
appearance: {
eyeColor: 'brown',
hairColor: {
primary: 'white',
secondary: undefined,
otherColors: ['black'],
},
sterilizedAt: undefined,
hasPuppies: false,
}
}
)
},
sterilizedAt: undefined,
hasPuppies: false,
},
});
```

@@ -104,3 +102,3 @@

haf.set('appearance.hairColor.secondary', undefined);
haf.set('appearance.hairColor.otherColors', ['black']) // This will overwrite existing array
haf.set('appearance.hairColor.otherColors', ['black']); // This will overwrite existing array

@@ -119,7 +117,7 @@ haf.set('name', 1); // type error

```typescript
haf.get('toys') // ['socks', 'toilet paper']
haf.get('toys'); // ['socks', 'toilet paper']
haf.append('toys', 'human hand', 'bone')
haf.append('toys', 'human hand', 'bone');
haf.get('toys') // ['socks', 'toilet paper', 'human hand', 'bone']
haf.get('toys'); // ['socks', 'toilet paper', 'human hand', 'bone']
```

@@ -126,0 +124,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