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

@harlem/utilities

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harlem/utilities - npm Package Compare versions

Comparing version 2.0.0-beta.0 to 2.0.0-beta.1

dist/esm/index.js

4

dist/index.d.ts

@@ -1,3 +0,5 @@

declare function clone<TValue = unknown>(value: TValue): TValue;
import { UnwrapRef } from 'vue';
declare function clone<TValue = unknown>(value: TValue): UnwrapRef<TValue>;
declare function lock<T extends object>(input: T, exclusions: (keyof T)[]): T;

@@ -4,0 +6,0 @@

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

// src/type/get-type.ts
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/type/get-type.ts
function getType(input) {

@@ -7,2 +7,5 @@ return Object.prototype.toString.call(input).slice(8, -1).toLowerCase();

// src/object/clone.ts
var _vue = require('vue');
function cloneIdentity(input) {

@@ -14,2 +17,7 @@ return input;

}
function cloneRegex(input) {
const clonedRegex = new RegExp(input.source);
clonedRegex.lastIndex = input.lastIndex;
return clonedRegex;
}
function cloneSymbol(input) {

@@ -43,5 +51,5 @@ return Object(Symbol.prototype.valueOf.call(input));

var CLONE_MAP = {
default: () => null,
null: () => null,
undefined: () => null,
default: cloneIdentity,
null: cloneIdentity,
undefined: cloneIdentity,
boolean: cloneBasic,

@@ -52,3 +60,3 @@ number: cloneBasic,

date: cloneBasic,
regexp: cloneBasic,
regexp: cloneRegex,
function: cloneIdentity,

@@ -67,3 +75,4 @@ symbol: cloneSymbol,

const cloner = CLONE_MAP[type] || CLONE_MAP.default;
return cloner(value);
const input = _vue.unref.call(void 0, value);
return cloner(input);
}

@@ -106,3 +115,3 @@

const nodes = isArray(path) ? path : path.split("/");
return nodes.reduce((branch, node) => branch?.[node], value);
return nodes.reduce((branch, node) => _optionalChain([branch, 'optionalAccess', _ => _[node]]), value);
}

@@ -123,12 +132,12 @@

}
export {
clone,
fromPath,
getType,
isArray,
isObject,
lock,
overwrite,
toPath
};
exports.clone = clone; exports.fromPath = fromPath; exports.getType = getType; exports.isArray = isArray; exports.isObject = isObject; exports.lock = lock; exports.overwrite = overwrite; exports.toPath = toPath;
//# sourceMappingURL=index.js.map
{
"name": "@harlem/utilities",
"amdName": "harlemUtilities",
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"license": "MIT",

@@ -9,9 +9,14 @@ "author": "Andrew Courtice <andrewcourtice@users.noreply.github.com>",

"homepage": "https://harlemjs.com",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": "./dist/index.js",
"unpkg": "./dist/index.global.js",
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/esm/index.js",
"unpkg": "dist/iife/index.js",
"jsdelivr": "dist/iife/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/index.js"
}
},
"keywords": [

@@ -36,3 +41,9 @@ "vue",

},
"gitHead": "fb160f38228a6bbfb1ba2670a8306be5f22e63f7"
"peerDependencies": {
"vue": "^3.2.0"
},
"devDependencies": {
"vue": "^3.2.0"
},
"gitHead": "3d065cc409a318566290127a0f23063eb397f480"
}
import getType from '../type/get-type';
import {
unref,
UnwrapRef
} from 'vue';
import type {

@@ -16,2 +21,9 @@ Constructable,

function cloneRegex(input: RegExp): RegExp {
const clonedRegex = new RegExp(input.source);
clonedRegex.lastIndex = input.lastIndex;
return clonedRegex;
}
function cloneSymbol(input: symbol): symbol {

@@ -56,11 +68,15 @@ return Object(Symbol.prototype.valueOf.call(input));

const CLONE_MAP = {
default: () => null,
null: () => null,
undefined: () => null,
boolean: cloneBasic,
number: cloneBasic,
string: cloneBasic,
default: cloneIdentity,
// Primitives
null: cloneIdentity,
undefined: cloneIdentity,
boolean: cloneBasic, // only for new Boolean()
number: cloneBasic, // only for new Number()
string: cloneBasic, // only for new String()
// Objects
error: cloneBasic,
date: cloneBasic,
regexp: cloneBasic,
regexp: cloneRegex,
function: cloneIdentity,

@@ -74,5 +90,5 @@ symbol: cloneSymbol,

export default function clone<TValue = unknown>(value: TValue): TValue {
export default function clone<TValue = unknown>(value: TValue): UnwrapRef<TValue> {
if (typeof value !== 'object' || value === null) {
return value;
return value as UnwrapRef<TValue>;
}

@@ -82,4 +98,5 @@

const cloner = CLONE_MAP[type] || CLONE_MAP.default;
const input = unref(value);
return cloner(value) as TValue;
return cloner(input) as UnwrapRef<TValue>;
}
import clone from '../src/object/clone';
import {
isReactive,
isRef,
reactive,
ref,
} from 'vue';
function getSimpleTypes(): Record<string, unknown> {

@@ -7,2 +14,3 @@ return {

und: undefined,
str: 'hello world',
func1: () => console.log('test'),

@@ -62,4 +70,23 @@ func2: function (a: number, b: number) {

test('Should unwrap reactive objects', () => {
const source = {
a: ref(4),
b: ref([1, 2, 3]),
c: {
d: reactive({
e: 1,
}),
},
};
const copy = clone(source);
expect(isRef(copy.a)).toBe(false);
expect(isRef(copy.b)).toBe(false);
expect(isReactive(copy.c.d)).toBe(false);
});
});
});

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