All Projects → WebReflection → proxy-pants

WebReflection / proxy-pants

Licence: ISC License
Secured and reliable Proxy based utilities for more or less common tasks.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to proxy-pants

Saws
A supercharged AWS command line interface (CLI).
Stars: ✭ 4,886 (+13472.22%)
Mutual labels:  utility, utilities
Gitlab Cli
Create a merge request from command line in gitlab
Stars: ✭ 224 (+522.22%)
Mutual labels:  utility, utilities
Utils
A collection of useful PHP functions, mini classes and snippets that you need and can use every day.
Stars: ✭ 750 (+1983.33%)
Mutual labels:  utility, utilities
Schematics Utilities
🛠️ Useful exported utilities for working with Schematics
Stars: ✭ 73 (+102.78%)
Mutual labels:  utility, utilities
youtube-unofficial
Access parts of your account unavailable through normal YouTube API access.
Stars: ✭ 33 (-8.33%)
Mutual labels:  utility, utilities
Lodash Php
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP
Stars: ✭ 412 (+1044.44%)
Mutual labels:  utility, utilities
Util
A collection of useful utility functions
Stars: ✭ 201 (+458.33%)
Mutual labels:  utility, utilities
Haxor News
Browse Hacker News like a haxor: A Hacker News command line interface (CLI).
Stars: ✭ 3,342 (+9183.33%)
Mutual labels:  utility, utilities
timestampy
🕒 Bunch of utilities useful when working with UNIX timestamps
Stars: ✭ 21 (-41.67%)
Mutual labels:  utility, utilities
gut
🍱 yet another collection of go utilities & tools
Stars: ✭ 24 (-33.33%)
Mutual labels:  utility, utilities
ios
CoThings's iOS application. CoThings is a realtime counter for shared things.
Stars: ✭ 13 (-63.89%)
Mutual labels:  utility, utilities
vmutils
cross platform library to manipulate and extract information of memory regions
Stars: ✭ 22 (-38.89%)
Mutual labels:  utility, utilities
assign-one-project-github-action
Automatically add an issue or pull request to specific GitHub Project(s) when you create and/or label them.
Stars: ✭ 140 (+288.89%)
Mutual labels:  utility, utilities
bat
Battery management utility for Linux laptops.
Stars: ✭ 107 (+197.22%)
Mutual labels:  utility, utilities
vscode-jump
🏃‍♂️ Jump/Select to the Start/End of a word in VSCode
Stars: ✭ 67 (+86.11%)
Mutual labels:  utility
memer-action
A GitHub Action for Programmer Memes xD
Stars: ✭ 21 (-41.67%)
Mutual labels:  utilities
plex
Oracle PL/SQL Export Utilities: Export Oracle APEX app, ORDS modules, all schema objects and table data in one go
Stars: ✭ 23 (-36.11%)
Mutual labels:  utilities
to-no-case
Remove an existing case from a string.
Stars: ✭ 15 (-58.33%)
Mutual labels:  utility
oc-bootstrapper
Easily bootstrap a new October CMS project
Stars: ✭ 86 (+138.89%)
Mutual labels:  utility
task-completed-checker-action
☑️ A GitHub action that checks if all tasks are completed in the pull requests.
Stars: ✭ 30 (-16.67%)
Mutual labels:  utility

proxy-pants

build status Coverage Status CSP strict

Social Media Photo by lan deng on Unsplash

Secured and reliable Proxy based utilities for more or less common tasks:

  • accessor to trap one or more accessors for any object
  • applier & caller to trap any borrowed callback/utility without needing to use .call or .apply to pass the context
  • bound to bind one or more methods all at once
  • bread & crumbs to track operations through paths (i.e. a.b.c.d) and namespaces
  • chain to trap once all inherited descriptors down the prototypal chain and automatically ensure the right accessor or method
  • extender to extend any object through weakly referenced behaviors, providing a new way to deal with state machines too, through the following features:
    • methods are always the same bound reference
    • properties are defined per extender and never directly attached to the source
    • accessors are also defined per each extender
    • multiple extenders calls to the same source preserve previous state, and any source can pass through multiple extenders without ever conflicting
  • own to destructure only own properties
  • secure to ensure local classes cannot be patched at runtime down their prototypal chain

accessor

// import {accessor} from 'proxy-pants/accessor';
import {accessor} from 'proxy-pants';

const {textContent} = accessor(document.body);

// get the current body text
textContent();

// set the new one
textContent('proxy pants!');

applier & caller

// import {applier, caller} from 'proxy-pants/function';
import {applier, caller} from 'proxy-pants';

const {hasOwnProperty, toString} = caller(Object.prototype);

// true
hasOwnProperty({any: 'object'}, 'any');

// [object Null]
toString(null);

const {fromCharCode} = applier(String);

const charCodes = (...args) => fromCharCode(String, args);
// <=>
charCodes(60, 61, 62);

bound

// import {bound} from 'proxy-pants/bound';
import {bound} from 'proxy-pants';

const map = new Map;
const {get, set, has} = bound(map);

// false
has('some');

// the map
set('some', 'value');

// true
has('some');

// 'value'
get('some');

bread & crumbs

// import {bread, crumbs} from 'proxy-pants/breadcrumbs';
import {bread, crumbs} from 'proxy-pants';

const namespace = {
  some: 'value',
  method(...args) {
    return this.some + args.length;
  },
  Class: class {}
};

const facade = crumbs({
  apply(path, args) {
    return bread(namespace, path)(...args);
  },
  construct(path, args) {
    const Class = bread(namespace, path);
    return new Class;
  },
  get(path, key) {
    return bread(namespace, path)[key];
  },
  has(path, key) {
    return key in bread(namespace, path);
  },
  set(path, key, value) {
    bread(namespace, path)[key] = value;
    return true;
  },
  // alias for deleteProperty(path, key) {}
  delete(path, key) {
    return delete bread(namespace, path)[key];
  }
});

facade.some;            // value
facade.method(1, 2, 3); // some3
new facade.Class;       // [object Namespace]
'some' in facade;       // true
facade.test = 'ok';
facade.test;            // ok
delete facade.test;     // true

chain

// import {chain} from 'proxy-pants/chain';
import {chain} from 'proxy-pants';

const asNode = chain(Node);
const asElement = chain(Element);

asNode(document.createTextNode('accessor')).data;
asElement(document.body).querySelector('method');

extender

// import {extender} from 'proxy-pants/extender';
import {extender} from 'proxy-pants';

const Magic = extender({
  // properties are per extender and weakly related
  isMagic: true,

  // accessors context is the original source/target
  get magic() {
    // this === source
    return Magic(this).isMagic;
  },

  // methods are always same bound method reference (except init)
  hasMagic() {
    // this === source
    return $(this).magic;
  },

  // a special method that helps setting up any reference once
  // bear in mind Magic(ref).init() won't be defined as own method
  init() {
    // this is implicitly invoked only the first time Magic(this) is used
  }
});

// it can be simplified per module as ...
const $ = Magic;

const source = {};
const target = Magic(source);

target.isMagic;     // true
target.magic;       // true
target.hasMagic();  // true

own

// import {own} from 'proxy-pants/own';
import {own} from 'proxy-pants';

const created = Object.create(
  {inherited: true},
  {prop: {value: true}}
);

const {inherited, prop} = own(created);

console.assert(!inherited);
console.assert(prop);

secure

// import {secure} from 'proxy-pants/secure';
import {secure} from 'proxy-pants';

const {
  Map,
  WekMap
} = secure(globalThis);

// both instances now can be used without
// possible issues down the prototypal chain
const map = new Map;
const wm = new WeakMap;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].