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

enmap

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enmap - npm Package Compare versions

Comparing version 6.0.0-beta1 to 6.0.0

docs/api.md

4

.eslintrc.json

@@ -8,6 +8,6 @@ {

"node": true,
"es2021": true
"es6": true
},
"parserOptions": {
"ecmaVersion": 2022,
"ecmaVersion": 2023,
"sourceType": "module"

@@ -14,0 +14,0 @@ },

@@ -0,0 +0,0 @@ export default {

{
"name": "enmap",
"version": "6.0.0-beta1",
"version": "6.0.0",
"description": "A simple database wrapper to make sqlite database interactions much easier for beginners, with additional array helper methods.",

@@ -9,3 +9,4 @@ "main": "src/index.js",

"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"docs": "node ./docs/build.js"
"build-api-docs": "node ./scripts/build-docs.js",
"build-docs": "cd docs && npx retype build"
},

@@ -37,6 +38,6 @@ "repository": {

"dependencies": {
"better-sqlite3": "^9.0.0",
"better-serialize": "^1.0.0",
"better-sqlite3": "^9.4.3",
"lodash-es": "^4.17.21",
"on-change": "^4.0.2",
"serialize-javascript": "^6.0.1"
"on-change": "^5.0.1"
},

@@ -48,8 +49,6 @@ "devDependencies": {

"jsdoc-to-markdown": "^8.0.0",
"limax": "^4.0.0"
"limax": "^4.0.0",
"retypeapp": "^3.5.0"
},
"types": "./typings/index.d.ts",
"volta": {
"node": "20.9.0"
}
"types": "./typings/index.d.ts"
}

@@ -0,0 +0,0 @@ # Enmap - Enhanced Maps

@@ -0,0 +0,0 @@ class CustomError extends Error {

@@ -1,9 +0,10 @@

/* global describe, test, beforeEach, afterEach, expect */
/* global describe, test, beforeEach, afterEach, expect, beforeAll */
import Enmap from '../';
const enmap = new Enmap({ inMemory: true });
describe('Standard Enmaps', () => {
let enmap;
beforeAll(() => {
enmap.clear();
})
describe('Basic Enmap', () => {
enmap = new Enmap('::memory::');
test('inserts primitive values', () => {

@@ -16,2 +17,3 @@ expect(enmap.set('simplevalue', 'this is a string')).not.toBe(null);

test('remembers primitive values', () => {
expect(enmap.length).toBe(4);
expect(enmap.get('simplevalue')).toBe('this is a string');

@@ -30,5 +32,13 @@ expect(enmap.get('boolean')).toBe(true);

});
test('can see if a value exists', () => {
expect(enmap.has('simplevalue')).toBe(true);
expect(enmap.has('nonexistent')).toBe(false);
});
test('can delete values', () => {
enmap.delete('simplevalue');
expect(enmap.get('simplevalue')).toBe(null);
});
test('can be cleared', () => {
enmap.clear();
expect(enmap.size).toBe(0);
expect(enmap.length).toBe(0);
});

@@ -38,4 +48,2 @@ });

describe('Advanced Data Types', () => {
enmap = new Enmap('::memory::');
test('supports arrays', () => {

@@ -94,3 +102,2 @@ expect(enmap.set('array', [1, 2, 3])).not.toBe(null);

set: new Set([123, 456]),
fn: function echo(arg) { return arg; },
re: /([^\s]+)/g,

@@ -101,5 +108,13 @@ // eslint-disable-next-line no-undef

expect(enmap.get('serialized', 'undef')).toBeUndefined();
expect(enmap.get('serialized', 'fn')('test')).toBe('test');
expect(enmap.get('serialized', 'map').get('hello')).toBe('world');
});
test('deleting data', () => {
enmap.delete('serialized', 'str');
expect(enmap.get('serialized', 'str')).toBeUndefined();
enmap.delete('serialized', 'obj.foo');
expect(enmap.get('serialized', 'obj.foo')).toBeUndefined();
enmap.delete('serialized');
expect(enmap.get('serialized')).toBeNull();
});
});

@@ -109,5 +124,7 @@ });

describe('Advanced Data Type Methods', () => {
let enmap;
beforeAll(() => {
enmap.clear();
});
beforeEach(() => {
enmap = new Enmap('::memory::');
enmap.clear();
enmap.set('obj1', {

@@ -117,2 +134,3 @@ prop: 'prop',

sub: { value: 'subvalue' },
arr: [1, 2, 3],
});

@@ -127,13 +145,9 @@ enmap.set('obj2', {

test('can findAll using both properties and path', () => {
expect(enmap.findAll('prop', 'prop').length).toBe(2);
expect(enmap.findAll('sub.value', 'subvalue').length).toBe(2);
test('can filter using both properties and path', () => {
expect(enmap.filter('prop', 'prop').length).toBe(2);
expect(enmap.filter('sub.value', 'subvalue').length).toBe(2);
expect(enmap.filter(value => value?.foo?.includes('pha')).length).toBe(1);
});
test('can find using both properties and path', () => {
// expect(enmap.find('prop', 'prop')).toEqual({
// prop: 'prop',
// foo: 'bar',
// sub: { value: 'subvalue' }
// });
expect(enmap.find('sub.value', 'subvalue')).toEqual({

@@ -143,57 +157,137 @@ prop: 'prop',

sub: { value: 'subvalue' },
arr: [1, 2, 3],
});
});
test('can check if value includes', () => {
expect(enmap.includes('arr1', 'one')).toBe(true);
expect(enmap.includes('arr1', 3)).toBe(true);
expect(enmap.includes('arr1', 'three')).toBe(false);
expect(enmap.includes('obj1', 2, 'arr')).toBe(true);
});
test('can iterate over truthy/falsey predicates', () => {
enmap.delete('arr1');
enmap.set('obj3', { prop: 'prop' });
expect(enmap.some('prop', 'prop')).toBe(true);
expect(enmap.some('notprop', 'prop')).toBe(false);
expect(enmap.every('prop', 'prop')).toBe(true);
expect(enmap.every('notprop', 'prop')).toBe(false);
expect(enmap.some(value => value?.prop === 'prop')).toBe(true);
expect(enmap.some(value => value?.prop === 'notprop')).toBe(false);
expect(enmap.every(value => value?.prop === 'prop')).toBe(true);
expect(enmap.every(value => value?.prop === 'notprop')).toBe(false);
});
test('can map over values', () => {
enmap.delete('arr1');
const mapped = enmap.map(value => value.prop);
expect(mapped).toEqual(['prop', 'prop']);
const manualMapped = enmap.map('prop');
expect(manualMapped).toEqual(['prop', 'prop']);
expect(enmap.map('sub.value')).toEqual(['subvalue', 'subvalue']);
});
test('can reduce over values', () => {
const reduced = enmap.reduce((acc, value) => value.prop ? acc + value.prop : acc, '');
expect(reduced).toBe('propprop');
});
});
describe('Basic Enmap Options', () => {
let enmap;
let baseObj;
beforeEach(() => {
baseObj = {
prop1: false,
prop2: 'thing',
prop3: [1, 2, 3],
obj: { thing: 'amajig' },
describe('partition', () => {
beforeAll(() => {
enmap.clear();
for (let i = 0; i < 10; i++) {
enmap.set(`${i}`, {
number: i,
isEven: i % 2 === 0,
});
};
});
afterEach(() => {
test('partition by function', () => {
const partitioned = enmap.partition((value) => {
return value.number % 2 === 0;
});
expect(partitioned[0].length).toBe(5);
expect(partitioned[1].length).toBe(5);
});
test('partition by property', () => {
const partitioned = enmap.partition('isEven', true);
expect(partitioned[0].length).toBe(5);
expect(partitioned[1].length).toBe(5);
});
});
describe('Enmap Observables', () => {
// This entire set of test was written by Copilot. What do you think?
beforeAll(() => {
enmap.clear();
enmap = null;
enmap.set('test', {
a: 1,
b: 2,
c: 3,
d: [1, 2, 3, 4],
e: { a: 'a', b: 'b', c: 'c' },
});
});
test('supports direct passing by reference (cloneLevel none)', () => {
enmap = new Enmap({ name: '::memory::', cloneLevel: 'none' });
enmap.set('foo', baseObj);
enmap.set('foo', 'other', 'prop2');
enmap.push('foo', 4, 'prop3');
// by reference modifies object properties at any level.
expect(baseObj.prop2).toBe('other');
expect(baseObj.prop3.length).toBe(4);
test('can observe a value', () => {
const obj = enmap.observe('test');
expect(obj.a).toBe(1);
obj.a = 2;
expect(enmap.get('test', 'a')).toBe(2);
});
test('supports shallow clones', () => {
enmap = new Enmap({ name: '::memory::', cloneLevel: 'shallow' });
enmap.set('foo', baseObj);
enmap.set('foo', 'other', 'prop2');
enmap.push('foo', 4, 'prop3');
// shallow clones do not allow base props to change in referenced object
expect(baseObj.prop2).toBe('thing');
// shallow clones still allow subprops to be modified, though.
expect(baseObj.prop3.length).toBe(4);
test('can observe a subproperty', () => {
const obj = enmap.observe('test', 'e');
expect(obj.a).toBe('a');
obj.a = 'b';
expect(enmap.get('test', 'e.a')).toBe('b');
});
test('supports deep clones', () => {
enmap = new Enmap({ name: '::memory::', cloneLevel: 'deep' });
enmap.set('foo', baseObj);
enmap.set('foo', 'other', 'prop2');
enmap.push('foo', 4, 'prop3');
// deep clones do not allow base props to change in referenced object
expect(baseObj.prop2).toBe('thing');
// deep clones do not allow sub props to be changed, either.
expect(baseObj.prop3.length).toBe(3);
test('can observe an array', () => {
const arr = enmap.observe('test', 'd');
expect(arr.length).toBe(4);
arr.push(5);
expect(enmap.get('test', 'd').length).toBe(5);
});
test('can observe a subproperty of an array', () => {
const arr = enmap.observe('test', 'd');
const obj = arr[0];
expect(obj).toBe(1);
arr[0] = 2;
expect(enmap.get('test', 'd.0')).toBe(2);
});
});
describe('sweep', () => {
beforeEach(() => {
enmap.clear();
for (let i = 0; i < 10; i++) {
enmap.set(`${i}`, {
number: i,
isEven: i % 2 === 0,
});
};
});
test('sweep by function', () => {
enmap.sweep((value) => {
return value.number % 2 === 0;
});
expect(enmap.size).toBe(5);
});
test('sweep by property', () => {
enmap.sweep('isEven', false);
expect(enmap.size).toBe(5);
});
});
describe('Basic Enmap Options', () => {
const localEnmap = new Enmap({ inMemory : true, ensureProps: true });
test('supports deep ensure() merge', () => {
enmap = new Enmap({ name: '::memory::', ensureProps: true });
const defaultValue = {

@@ -203,5 +297,5 @@ foo: 'bar',

};
enmap.set('obj', {});
enmap.ensure('obj', defaultValue);
expect(enmap.get('obj', 'bar.foo')).toBe(1);
localEnmap.set('obj', {});
localEnmap.ensure('obj', defaultValue);
expect(localEnmap.get('obj', 'bar.foo')).toBe(1);
});

@@ -211,2 +305,7 @@ });

describe('Enmap Advanced Options', () => {
class ExampleClass {
constructor(id) {
this.id = id;
}
}
let enmap;

@@ -221,9 +320,10 @@ const defaultData = {

afterEach(() => {
enmap.close();
enmap.clear();
enmap = null;
});
test('supports autoEnsure', () => {
enmap = new Enmap({ name: '::memory::', autoEnsure: defaultData });
enmap = new Enmap({ inMemory: true, autoEnsure: defaultData });
expect(enmap.get('test')).toEqual(defaultData);
expect(enmap.size).toBe(1);
expect(enmap.length).toBe(1);
enmap.set('test', 'a', 'a');

@@ -242,11 +342,14 @@ expect(enmap.get('test')).toEqual({

test('supports serializers', () => {
defaultData.c = new ExampleClass(3);
enmap = new Enmap({
name: '::memory::',
serializer: (data, key) => ({
inMemory: true,
serializer: (data) => ({
...data,
a: 'modified',
c: data.c.id,
}),
deserializer: (data, key) => ({
deserializer: (data) => ({
...data,
a: 1,
c: new ExampleClass(data.c),
}),

@@ -259,4 +362,4 @@ });

.get('test');
expect(data.value).toBe('{"a":"modified","b":2,"c":3,"d":[1,2,3,4],"e":{"a":"a","b":"b","c":"c"}}');
expect(data.value).toBe('{"t":0,"v":{"a":{"t":1,"v":"modified"},"b":{"t":2,"v":2},"c":{"t":2,"v":3},"d":{"t":4,"v":[{"t":2,"v":1},{"t":2,"v":2},{"t":2,"v":3},{"t":2,"v":4}]},"e":{"t":0,"v":{"a":{"t":1,"v":"a"},"b":{"t":1,"v":"b"},"c":{"t":1,"v":"c"}}}}}');
});
});

@@ -187,3 +187,3 @@ declare module 'enmap' {

* @param path The path to the property to modify inside the value object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @example

@@ -215,3 +215,3 @@ * // Settings Properties

* @param path Optional. The property to retrieve from the object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @example

@@ -283,3 +283,3 @@ * const myKeyValue = enmap.get("myKey");

* @param path Required. The property to modify inside the value object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @param val Required. The value to apply to the specified property.

@@ -296,3 +296,3 @@ * @returns The enmap.

* @param path Optional. The path to the property to modify inside the value object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @param allowDupes Optional. Allow duplicate values in the array (default: false).

@@ -315,3 +315,3 @@ * @example

* @param path Required. The name of the array property to push to.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @param val Required. The value push to the array property.

@@ -385,3 +385,3 @@ * @param allowDupes Allow duplicate values in the array (default: false).

* @param path Required. The property to retrieve from the object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @return The value of the property obtained.

@@ -397,3 +397,3 @@ */

* @param path Optional. If presents, ensures both the key exists as an object, and the full path exists.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @example

@@ -419,3 +419,3 @@ * // Simply ensure the data exists (for using property methods):

* @param path Optional. The property to verify inside the value object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @example

@@ -434,3 +434,3 @@ * if(enmap.has("myKey")) {

* @param path Required. The property to verify inside the value object or array.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @return Whether the property exists.

@@ -445,3 +445,3 @@ */

* @param path Optional. The name of the property to remove from the object.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @returns The enmap.

@@ -455,3 +455,3 @@ */

* @param path Required. The name of the property to remove from the object.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
*/

@@ -474,3 +474,3 @@ public deleteProp(key: K, path: string): void;

* @param path Optional. The name of the array property to remove from.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3".
* Should be a path with dot notation, such as "prop1.subprop2.subprop3".
* If not presents, removes directly from the value.

@@ -487,3 +487,3 @@ * @returns The enmap.

* @param path Required. The name of the array property to remove from.
* Can be a path with dot notation, such as "prop1.subprop2.subprop3"
* Should be a path with dot notation, such as "prop1.subprop2.subprop3"
* @param val Required. The value to remove from the array property.

@@ -490,0 +490,0 @@ * @returns The enmap.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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