Options
All
  • Public
  • Public/Protected
  • All
Menu

@corefunc/v8

CoreFunc V8

CoreFunc V8

🇻8️ JavaScript V8 engine specific utilities.

NPM Version NPM Downloads TypeScript Typings

Reference

"Base64"

base64Decode(base64Text, encoding, start, end) Decodes to a string according to the specified character encoding in encoding.
import { base64Decode } from "@corefunc/v8/base64/decode";

// "example text"
console.log(base64Decode("ZXhhbXBsZSB0ZXh0"));

"CLI"

argvParse() Parses `process.argv` string.
import { argvParse } from "@corefunc/v8/cli/argv-parse";

console.dir(argvParse());
// "calc-md5=movie.mp4"
// { 'calc-md5': 'movie.mp4' }
envParse() Parses `process.env` object.
import { envParse } from "@corefunc/v8/cli/env-parse";

console.dir(envParse());
// {  SHELL: "/bin/zsh", SPACESHIP_VERSION: 3.16 }

"Clone"

clone(value, setPrototype) Deep clone object. Note: don't use on objects containing Functions.
import { clone } from "@corefunc/v8/clone/clone";

const obj = { prop: "original" };
const array = [obj];
const clonedArray = clone(array);

array[0].prop = "changed";

// [ { prop: 'changed' } ]
console.log(array);
// [ { prop: 'original' } ]
console.log(clonedArray);
import { clone } from "@corefunc/v8/clone/clone";

class Omega {
  x = 1;
  y = 2;
}
const omegaOne = new Omega();
const omegaTwo = clone(omegaOne, true);

omegaOne.x = -10;

// Omega { x: -10, y: 2 }
console.log(omegaOne);
// Omega { x: 1, y: 2 }
console.log(omegaTwo);
import { clone } from "@corefunc/v8/clone/clone";

const obj = { prop: "original" };
const setOriginal = new Set([obj]);
const setCloned = clone(setOriginal);

obj.prop = "changed";

// Set(1) { { prop: 'changed' } }
console.log(setOriginal);
// Set(1) { { prop: 'original' } }
console.log(setCloned);
import { clone } from "@corefunc/v8/clone/clone";

const obj = { prop: "here is my password" };
const mapFirst = new Map([["secret", obj]]);
const mapSecond = clone(mapFirst);
const secret = mapFirst.get("secret");

secret.prop = "there is no secret anymore";

// Map(1) { 'secret' => { prop: 'there is no secret anymore' } }
console.log(mapFirst);
// Map(1) { 'secret' => { prop: 'here is my password' } }
console.log(mapSecond);
import { clone } from "@corefunc/v8/clone/clone";
const alpha = new Error(`Just error`);
const beta = clone(alpha);

alpha.message = `Now it's not`;

// `Now it's not`
console.log(alpha.message);
// `Just error`
console.log(beta.message);
cloneMarshalling(value) Deep clone object and sets the prototype. Note: don't use on objects containing Functions.
import {
  cloneMarshalling,
} from "@corefunc/v8/clone/clone-marshalling";

class Omega {
  x = 1;
  y = 2;
}
const omegaOne = new Omega();
const omegaTwo = cloneMarshalling(omegaOne);

omegaOne.x = -10;

// Omega { x: -10, y: 2 }
console.log(omegaOne);
// Omega { x: 1, y: 2 }
console.log(omegaTwo);
cloneShallow(value) Deep clone any object to plain object.
import {
  cloneShallow,
} from "@corefunc/v8/clone/clone-shallow";

class Omega {
  x = 1;
  y = 2;
}
const omegaOne = new Omega();
const omegaTwo = cloneShallow(omegaOne);

omegaOne.x = -10;

// Omega { x: -10, y: 2 }
console.log(omegaOne);
// { x: 1, y: 2 }
console.log(omegaTwo);

"Deserialize"

deserializeFromString(binaryString) Deserialize string to object value.
import {
  deserializeFromString,
} from "@corefunc/v8/deserialize/from-string";

class Omega {
  x = 1;
  y = 2;
}
const binaryString = `ÿ\ro"\x01xI\x02"\x01yI\x04{\x02`;
const obj = deserializeFromString(binaryString);
const omega = deserializeFromString(binaryString, Omega);

// { x: 1, y: 2 }
console.log(obj);
// Omega { x: 1, y: 2 }
console.log(omega);

"Generate"

generateNumber(minimum, maximum) Secure random number generator. Integers only.
import {
  generateNumber,
} from "@corefunc/v8/generate/number";

const integer = await generateNumber(-100, 100);
// 56
console.log(integer);
generateTimeStamp(start, end) Generates timestamp.
import {
  generateTimeStamp,
} from '@corefunc/v8/generate/time-stamp';

const timeStamp = generateTimeStamp(0, 31);
// "2000123101020312345678901234567"
console.log(timeStamp);
generateUuid4() Generates a random RFC 4122 version 4 UUID.
import {
  generateUuid4,
} from "@corefunc/v8/generate/uuid4";

// "71ce5138-c908-47b0-b599-327bcec8d213"
console.log(generateUuid4());
generateUuid5() Generates a RFC 4122 version 5 UUID.
import {
  generateUuid5,
} from "@corefunc/v8/generate/uuid5";

const name = `{"a":1}`;
const nameSpace = "924a63b2-7e67-435e-94b7-57b5f806b105";
// "a923cf68-cd80-577c-981d-c219fbcb3bee"
console.log(generateUuid5(name, nameSpace));

"Serialize"

serializeToString(value) Serialize value to binary string.
import {
  serializeToString,
} from "@corefunc/v8/serialize/to-string";

class Omega {
  x = 1;
  y = 2;
}
const omega = new Omega();
const binaryString = serializeToString(omega);

// `ÿ\ro"\x01xI\x02"\x01yI\x04{\x02`
console.log(binaryString);

See also

💾 My other projects

Open Source

Generated using TypeDoc