A basic helper to simplify relations among values, based on WeakRef

Overview

transform-once

build status Coverage Status CSP strict

A basic helper to simplify relations among values. Optionally compatible with WeakValue too.

import transformOnce from 'transform-once';

const $ = transformOnce(value => {
  return {object: Math.random()};
});

// references are transformed once
$(globalThis) === $(globalThis):

// transformed values are returned too
$(globalThis) === $($(globalThis)):

$(globalThis);
// {object: 0.123456789}

Provide WeakRef Ability

If the input needs to be referenced, it is possible to use WeakRef based utility, such as WeakValue to automatically cleanup once the related reference is gone.

import transformOnce from 'transform-once';
import WeakValue from 'weak-value';

// pass as context all needed classes (which are these three)
const transform = transformOnce.bind({WeakMap, WeakSet, WeakValue});

// now create a transformer that works with primitives too
const $ = transform(value => ({[typeof value]: Math.random()}));

$(1) === $(1);
$(1) === $($(1));
$($) === $($($));
$(1);
// {number: 0.123456789}

Alternative, it is also possible to pass a Map instead, but it's up to the program to clear its content, whenever it's necessary.

import transformOnce from 'transform-once';
const transform = transformOnce.bind({WeakMap, WeakSet, WeakValue: Map});

// same as before but primitives are not weakly referenced
const $ = transform(value => ({[typeof value]: Math.random()}));

By default this module does not provide any weakly reference mechanism so each time a primitive is passed along, it will be transformed.

You might also like...

Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

实时计算(English Version) 运用实时计算技术、Web 技术构建一个大数据看板来解决问题。其中实用技术包括Mysql、Kafka、Flink、Redis、Flask和Echarts 目录 1.问题需求 2.方案分析 3.安装环境 4.环境启动命令和运行代码的方法 5.代码目录结构说明

Jan 8, 2022

A serverless AWS expense tracker API. AWS Lambda functions, API gateway, and Dynamodb are among the ingredients.

AWS-Serverless-API A serverless AWS expense tracker API. AWS Lambda functions API gateway Dynamodb Endpoints Create a new expense: Method: POST Body f

Jul 16, 2022

A health-focused app for users to be able to track workouts and nutritional data with a social media component to inspire friendly competition among the users.

A health-focused app for users to be able to track workouts and nutritional data with a social media component to inspire friendly competition among the users.

Aug 26, 2022

A tool to simplify importing custom assets in Minecraft

BAMO - Block And Move On A tool to simplify importing custom assets in Minecraft Currently only allows you to quickly prototype models in-game, but fu

Jul 15, 2022

'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style(event driven architecture). For message broker, light weight Redis Stream is used and for event store, the well known NoSQL database, MongoDB, is used.

Jan 4, 2023

A browser extension to simplify web pages and hide distracting things like hide cookie banners, auto-playing videos, sidebars, etc

A browser extension to simplify web pages and hide distracting things like hide cookie banners, auto-playing videos, sidebars, etc

Unclutter Browser Extension A browser extension to simplify web pages and hide distracting things like hide cookie banners, auto-playing videos, sideb

Jan 9, 2023

Wen? Now! A library to simplify your Web3 data fetching.

Wen Connect? Now! Minimalistic library for Web3 user interfaces. Seamless connection flows to Metamask. Stateless sessions that work anywhere (client,

Jul 20, 2022

This solution aims to simplify the implementation of login using SPID or similar services, such as CIE and eIDAS

This solution aims to simplify the implementation of login using SPID or similar services, such as CIE and eIDAS. It supports both the use of ADFS and B2C as identity federators.

Dec 2, 2022

It's a javascript Class which contains utility methods that simplify working with google maps web SDK

About GoogleMapsJSHelper It's a javascript Class which contains utility methods that simplify working with google maps web SDK Note: i used ES7 Class

Jul 23, 2022

🛫 TypeScript Starter template to simplify creating your next npm package.

TypeScript Starter Kit This is an opinionated TypeScript Starter kit to help kick-start development of your next npm package. 💡 Get Started Luckily,

Sep 27, 2022

🛫 TypeScript Starter template to simplify creating your next npm package.

TypeScript Starter Kit This is an opinionated TypeScript Starter kit to help kick-start development of your next npm package. 💡 Get Started Luckily,

May 19, 2022

Simplify the installation of a Silverstripe Dev Environment.

silverstripe docker starter Simplify the installation of a Silverstripe Dev Environment. The silverstripe docker starter is based on the silverstripe/

Jul 7, 2022

Simplify gnome-extensions development

Simplify gnome-extensions development

GISP GISP Is a Starter Pack About GISP is a project to simplify 🙏 gnome-extensions development. There're hundrends (maybe thousands?) of javascript d

Jul 18, 2022

A library to simplify the https://photop.live REST api.

Photop.js Thanks a lot to stalicites (qa#1337) for writing the documentation... Photop.js is a library created by IMPixel, and used to accomplish crea

Jul 30, 2022

A command line application to simplify the git workflow on committing, pushing and others commands.

Git-Suite A command line application to simplify the git workflow on committing, pushing and others commands. Prerequisites Install Node Package Manag

Aug 10, 2022

BASIC is a web application contains basic applications related to studies, love, health, weather, productivity. This project aim to simply the user's life in anyway.

BASIC is a web application contains basic applications related to studies, love, health, weather, productivity. This project aim to simply the user's life in anyway.

BASIC is a web application contains basic applications related to studies, love, health, weather, productivity. This project aim to simply the user's life in anyway. Supported by all operating system, need an internet connection for working properly.

Dec 19, 2021

This project will be a basic website that allows users to add/remove books from a list. The main objective is to understand how to use JavaScript objects and arrays and dynamically modify the DOM and add basic events.

Awesome-books Awesome Books This project will be a basic website that allows users to add/remove books from a list. This project is part of the Microv

Oct 3, 2022

Basic website that allows users to add/remove books from a list. Achieved using JavaScript objects and arrays, dynamically modifying the DOM and adding basic events.

Awesome Books Basic website that allows users to add/remove books from a list. Achieved using JavaScript objects and arrays, dynamically modifying the

Dec 20, 2022

Automatically persist your forms' text and select field values locally, until the form is submitted.

Garlic.js Garlic.js allows you to automatically persist your forms' text and select field values locally, until the form is submitted. This way, your

Dec 21, 2022
Owner
Andrea Giammarchi
Web, Mobile, IoT and all Web & JS things since 00's
Andrea Giammarchi
Simple and elegant component-based UI library

Simple and elegant component-based UI library Custom components • Concise syntax • Simple API • Tiny Size Riot brings custom components to all modern

Riot.js 14.7k Jan 4, 2023
A declarative, HTML-based language that makes building web apps fun

A declarative, HTML-based language that makes building web apps fun ?? Docs ∙ Try Online ∙ Contribute ∙ Get Support Intro Marko is HTML re-imagined as

Marko 12k Jan 3, 2023
App development framework based on cocos creator3.1.1

todo: Waiting for English translation cx-cocos App development framework based on cocos creator3.1.1 一个基于cocos creator3.1.1的应用App和游戏开发框架 关键词:cocos cre

null 63 Dec 7, 2022
Kunlun architecture element generation based on Angular schematics 🎬

A fullstack(NestJS、React) framework for building efficient and scalable applications. Description The Kunlun CLI is a command-line interface tool that

图灵人工智能研究院前端技术团队 8 Aug 1, 2022
A labeler component that Lays out text and overlays textual decorations like labels, predictions, and relations based on given data and handles user interactions on tokens.

react-text-annotator react-text-annotator is a labeler component that: Lays out text and overlays textual decorations like labels, predictions, and re

Microsoft 25 Dec 11, 2022
Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values.

@suchipi/is Functions for testing the types of JavaScript values, cross-realm. Has testers for all standard built-in objects/values. Usage import { is

Lily Skye 5 Sep 8, 2022
Um bot de suporte feito usando threads para o Discord, 100% customizável, feito em JavaScript e inspirado no Rio Helper do servidor Elixir Lab e na Loritta Helper do serivdor de suporte da Loritta.

Ticket Bot Um bot de suporte feito usando threads para o Discord, 100% customizável, feito em JavaScript e inspirado no Rio Helper do servidor Elixir

ADG 6 Dec 21, 2022
A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Hana Yabuki 5 Jul 10, 2022
null 136 Dec 30, 2022
A student-made, student-tailored Firefox add-on for Veracross. Provides ease of navigation in Veracross, among with other quality of life features. More features in progress.

Check out the Chrome version! This release is version 1.0.0, so the only feature it has is clickable links to the dropbox from the classpage. Any comm

Webb School CS Club 3 Nov 25, 2022