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

@randajan/jet-core

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@randajan/jet-core

[![NPM](https://img.shields.io/npm/v/@randajan/jet-core.svg)](https://www.npmjs.com/package/@randajan/jet-core) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-97.53%
Maintainers
1
Weekly downloads
 
Created
Source

@randajan/jetpack

NPM JavaScript Style Guide

Install

npm install @randajan/jet-core

or

yarn add @randajan/jet-core

About

Goal is to create ecosystem for javascript types with possibility to define custom types. This package provide easy and deep objects map and comparing, generic creating, filtering by types, content & other stuff

Main content

jet.type

Reserved function-structure for main jet functionality

  • Arguments
    • any: any variable
    • all: boolean (return all types?)
  • Return
    • all=false || undefined: top type of variable
    • all=true: array with all types of variable sorted by its priority
  • Example
    • jet.type([], true) === ["arr", "object"];
    • jet.type(RegExp()) === "regex";

jet.type.define

Defining custom types for detecting, creating and copying

  • Arguments
    • name: string (name of the type)
    • constructor: class
    • opt: object
      • rank: number (>= 0)
      • create: function (creating new instance)
      • is: function (verify type of variable)
      • full: function (check if variable is full)
      • copy: function (perform copy)
      • rnd: function (create with random content)
      • keys: function (array of keys for mapable types)
      • vals: function (array of values for mapable types)
      • pairs: function (array of entries for mapable types)
      • get: function (get key for mapable types)
      • set: function (set key for mapable types)
      • rem: function (rem key for mapable types)
    • custom: object (functions that should be appended to jet.*)
  • Return
    • true when successfully defined
  • Example
    • jet.type.define("Arr", Array, { rank:-1, create:x=>new Array(x), copy:x=>Array.from(x) } );
    • jet.type.define("Ele", Element, { rank:-1 }, { find:query=>document.querySelector(query) });

jet.type.isFull

Catching empty mapable objects and NaN

  • Arguments
    • any: any variable
  • Return
    • true when variable is full
  • Example
    • jet.is.full([]) === false;
    • jet.is.full({foo:bar}) === true;

jet.type.isMapable

Return true on any type of variable that has mapable=true on its type definition

  • Arguments
    • any: any variable
  • Return
    • true when variable is mapable
  • Example
    • jet.is.map([]) === true
    • jet.is.map({}) === true;
    • jet.is.map("foo") === false;

jet.*

Will create instance requested * type (use without "new")

  • Arguments
    • ...args: will be passed to the creating function
  • Return
    • new instance
  • Example
    • jet.arr("foo", "bar") == ["foo", "bar"];
    • jet.obj() == {};
    • jet.ele() ==
      ;

jet.*.is

Check the passed type with result from instanceof compare || jet.type

  • Arguments
    • any: any variable
    • inclusive: boolean
  • Return
    • inclusive=true: true when the type is included in result of jet.type all=true
  • Example
    • jet.Arr.is([]) === true;
    • jet.Obj.is([]) === false;
    • jet.Obj.is([], true) === true;
    • jet.RegExp.is(RegExp()) === true;

jet.*.isFull

Same as jet.type.isFull but without type detection

jet.*.copy

Will create copy of instance

  • Arguments
    • any: any variable
  • Return
    • new instance or the old if there isn't defined copy function
  • Example
    • jet.obj.copy({a:1}) == Object.assign({}, {a:1});
    • jet.arr.copy(["foo", "bar"]) == Array.from(["foo", "bar"]);

jet.*.only / .tap / .full / .pull

Used for selecting, filtering, creating or copying variables

  • Arguments
    • ...args: any variable (will be tested in order until the type will match)
  • Return
    • only: undefined when there is no match
    • full: same as only but variable must be full
    • tap: same as only but try to create the type when there is no match
    • pull: same as tap but try to copy variable if there is match
  • Example
    • jet.str.only(1, "foo", [], ["bar"], {foo:"bar"}) == "foo";
    • jet.arr.tap(1, "foo", [], ["bar"], {foo:"bar"}) == [];
    • jet.arr.full(1, "foo", [], ["bar"], {foo:"bar"}) == ["bar"];
    • jet.regex.only(1, "foo", [], ["bar"], {foo:"bar"}) == null;
    • jet.regex.tap(1, "foo", [], ["bar"], {foo:"bar"}) == RegExp();
    • jet.obj.pull(1, "foo", [], ["bar"], {foo:"bar"}) == {foo:"bar"}

jet.Map.vals / .keys / .pairs / .get / .set / .rem

Handle mapable objects (it requires defined type)

  • Arguments
    • any: any variable
    • key: any variable (usually string or number)
    • val: any variable (used just for for set function)
  • Return
    • result from perform operation against the defined type_
  • Example
    • jet.map.get({foo:"bar"}, "bar") === "bar";

jet.Map.dig

Return value from deep nested object

  • Arguments
    • any: any mapable variable
    • path: string or Array (even nested Array)
    • def: any
  • Return
    • find value or def when no value was found
  • Example
    • jet.map.dig({foo:["bar"]}, "foo.0") == "bar";
    • jet.map.dig({foo:["bar"]}, ["foo", 1], "foo") == "foo";

jet.Map.it / .of

Map any mapable object by default: Object, Array, Set, Map, Pool

  • Arguments
    • any: any mapable variable
    • fce: function(val, key, path) (handler)
    • deep: boolean (recursive maping)
  • Return
    • it: count items in structure
    • of: copy of structure with result from handler function
  • Example
    • jet.map.it({foo:"bar"}, =>) == 1;
    • jet.map.of({foo:"bar"}, =>"foo"+) == {foo:"foobar"};

jet.Fce.run

Will run every function that will discover without collecting results

  • Arguments
    • any: any (function || array/object with functions
    • ...args: arguments will be passed to every call
  • Return
    • any=function: true when it was run successfully
    • any=array/object: count of succesfully runned functions
  • Example
    • jet.fce.run(=>console.log()) === true console: "foo"

License

MIT © randajan

Keywords

FAQs

Package last updated on 25 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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