The xphage.js package!

Overview

X Phage

X Phage is a highly organised JavaScript utility library!

Stars

Install

npm i xphage

Import

CJS

const _ = require('xphage')

ESM

import * as _ from 'xphage'

Integrate

X Phage is home to some of the most powerful methods in existence!

  • _.eq checks if multiple values are identical and works with Array and Object!
  • _.must serves as a callback function that dynamically converts String to Boolean expressions to compare Object types!
  • _.countif counts the number of items in an Array that satisfy the dynamic String expression!

X Phage still has much more to offer. Take a look for yourself!

console.log(_.eq([], []))
console.log(_.eq([0, 'text'], [0, 'text']))
console.log(_.eq([0, 'text', [], {}], [0, 'text', [], {}]))
console.log(_.eq({}, {}))
console.log(_.eq({ a: 0 }, { a: 0 }))
console.log(_.eq({ a: 0, b: [] }, { a: 0, b: [] }))
// true

/* Array */

console.log(_.nth(['first', 'last'], -1))
// last

for (let num of _.range(10, 0)) {
  console.log(num)
}
// 10 9 8 7 6 5 4 3 2 1
for (let num of _.range(0, 10, 2)) {
  console.log(num)
}
// 0 2 4 6 8 

console.log(_.sum([1, 2, 3, 4]))
// 10

console.log(_.includes([0, 'text', [], {}], {}))
// true
console.log(_.includesBy([0, 1, 2, 3], 3.5, Math.floor))
// true

console.log(_.uniq([0, 'text', 'text', [], {}, {}]))
// [0, 'text', [], {}]

console.log(_.uniqBy([
  { id: 0 },
  { id: 1 },
  { id: 0 },
  { id: 2 },
], 'id'))
// [{ id: 0 }, { id: 1 }, { id: 2 }]
console.log(_.uniqBy([2, 1.5, 1, 3.5], Math.floor))
// [1, 2, 3.5]

console.log(_.uniqSorted([1, 1, 1, 2, 3, 3]))
// [1, 2, 3]

console.log(_.uniqSortedBy([1, 1.5, 2, 3.5], Math.floor))
// [1, 2, 3.5]

console.log(_.chunk([0, 'text', [], {}], 3))
// [[0, 'text', []], [{}]]

const users = [
  {
    name: 'John',
    age: 18,
    deleted: false
  },
  {
    name: 'Jane',
    age: 13,
    deleted: false
  },
  {
    name: 'Bob',
    age: 69,
    deleted: true
  },
]

console.log(_.countif(users, '.age > 13'))
// 2
console.log(_.countif(users, ['&&', '.age > 13', '.deleted === false']))
// 1

console.log(_.filter(users, _.must({ age: '> 16' })))
// [{ name: 'John', age: 18, deleted: false }, { name: 'Bob', age: 69, deleted: true }]
console.log(_.filter(users, { age: 13 })) // _.matches shorthand
// [{ name: 'Jane', age: 13, deleted: false }]
console.log(_.filter(users, ['name', 'John'])) // _.matchesProperty shorthand
// [{ name: 'John', age: 18, deleted: false }]
console.log(_.filter(users, 'deleted')) // _.property shorthand
// [{ name: 'Bob', age: 69, deleted: true }]

console.log(_.distill(users, _.must({ age: ['&&', '>= 13', '<= 18'] })))
// [[John, Jane], [Bob]]
console.log(_.distill(users, { age: 13 })) // _.matches shorthand
// [[Jane], [John, Bob]]
console.log(_.distill(users, ['name', 'John'])) // _.matchesProperty shorthand
// [[John], [Jane, Bob]]
console.log(_.distill(users, 'deleted')) // _.property shorthand
// [[Bob], [John, Jane]]

console.log(_.find(users, _.must({ age: '> 16' })))
// { name: 'John', age: 18, deleted: false }
console.log(_.find(users, { age: 13 })) // _.matches shorthand
// { name: 'Jane', age: 13, deleted: false }
console.log(_.find(users, ['name', 'John'])) // _.matchesProperty shorthand
// { name: 'John', age: 18, deleted: false }
console.log(_.find(users, 'deleted')) // _.property shorthand
// { name: 'Bob', age: 69, deleted: true }

console.log(_.findIndexes(users, _.must({ age: '> 16' })))
// [0, 2]
console.log(_.findIndexes(users, { age: 13 })) // _.matches shorthand
// [1]
console.log(_.findIndexes(users, ['name', 'John'])) // _.matchesProperty shorthand
// [0]
console.log(_.findIndexes(users, 'deleted')) // _.property shorthand
// [2]

console.log(_.zip(['id', 0, 1, 2], ['username', 'int', 'bob', 'npm']))
// [['id', 'username'], [0, 'int'], [1, 'bob'], [2, 'npm']]

console.log(_.search([1, 2, 3], 2))
// 1
console.log(_.search([1, 2, 3], 4))
// -1

console.log(_.searchFit([1, 2, 3], 1))
// [0]
console.log(_.searchFit([1, 2, 3], 0))
// [0, 2]

const nums = [1, 2, 3]
console.log(_.insert(4, nums, 3))
// [1, 2, 3, 4]
console.log(nums)
// [1, 2, 3, 4] (mutated)
console.log(_.insert(0, nums, _.searchFit(nums, 0)[0]))
// [0, 1, 2, 3, 4]

console.log(_.insertSorted(1.5, nums))
// [0, 1, 1.5, 2, 3, 4]
You might also like...

A NPM package powered by Yeoman that generates a scaffolding boilerplate for back-end workflow with Node.js.

generator-noderplate Generate Node.js starter files with just one command! We have deployed a npm package that will generate a boilerplate for nodejs

Jan 24, 2022

💶 The package allows you accept payment using Lazerpay in your react native mobile app ⚡️

💶 The package allows you accept payment using Lazerpay in your react native mobile app ⚡️

Lazerpay Official react-native sdk Lazerpay SDK allows you accept payments easily in your react-native application Installation npm install lazerpay-r

Dec 24, 2022

Find stale dependencies in the package.json file(s).

staledeps Find stale dependencies in the package.json file(s). Installation npm install -g staledeps Or simply using npx, the package runner bundled

Dec 15, 2022

Detect npm packages by author name in your package-lock.json or yarn.lock.

detect-package-by-author Detect npm packages by author name in your package-lock.json or yarn.lock. Install Install with npm: # Not Yet Publish # npm

Jan 11, 2022

A lightweight (1Kb) JavaScript package to facilitate a11y-compliant tabbed interfaces

A11y Tabs A lightweight (1Kb) JavaScript package to facilitate a11y-compliant tabbed interfaces. Documentation ↗ Demo on Codepen ↗ Features: Support

Nov 20, 2022

This package includes the sensible ESLint configuration used by our team

TypeScript + Prettier ESLint configuration for CasterlyApp team (and others)

Jan 26, 2022

High performance (de)compression in an 8kB package

fflate High performance (de)compression in an 8kB package Why fflate? fflate (short for fast flate) is the fastest, smallest, and most versatile pure

Dec 28, 2022

This package is an open source extension for MikroORM, which enables Nested Set Tree for your needs

MikroORM nested set This package is an open source extension for MikroORM, which enables Nested Set Tree for your needs Disclaimer For now, this packa

Dec 15, 2022

A Compiler npm Package.

vcompiler 🎉 Version 1.x is live ! 🎉 Introducation It is the npm package for the compilation of the code. Currently it supports the following program

May 30, 2022
Owner
X Phage
Open Source Frameworks and Libraries!
X Phage
This package is for developers to be able to easily integrate bad word checking into their projects.\r This package can return bad words in array or regular expression (regex) form.

Vietnamese Bad Words This package is for developers to be able to easily integrate bad word checking into their projects. This package can return bad

Nguyễn Quang Sáng 8 Nov 3, 2022
Multi-platform node package bundle to a package.json.

dmpc Multi-platform node package bundle to a package.json. install ### npm mode npm i -g @kingsword/dmpc ### yarn mode yarn global add @kingsword/dmp

Kingsword 2 Oct 16, 2022
Zero dependencies, lightweight, and asynchronous https requests package.

This project is a Work in Progress and currently in development. The API is subject to change without warning. A small fetching package for super simp

Ray Arayilakath 11 Dec 8, 2022
NPM Package that simplifies Auth with Google OAuth2 🔐

Node Google OAuth2 ?? A simple authentication flow for Google OAuth2 Explore the docs » Report Bug Table of Contents About The Project Getting Started

Adarsh C 8 Jun 17, 2022
portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project Those days of manually updating portfolio website after every new project made are gone ⚡ Yesss . . . you read that right. ?? portfo

Gaurav Gulati 15 Aug 3, 2021
A package to toggle properties of your HTML tags.

Toggler A package(atleast the code) to toggle properties of tags. I mostly use toggle classes while making a switch theme method, button interaction e

chandra sekhar pilla 6 Jan 9, 2022
JavaScript package for predictive data analysis and machine learning

scikit.js JavaScript package for predictive data analysis and machine learning. Generic math operations are powered by Tensorflowjs core layer. We are

JSdata 74 Jan 6, 2023
Make sure a specific version and package-manger to be used in project.

pm-keeper A simple way to force package-manager in your project. usage Add a preinstall script in your project's package.json, link this: { "scripts

阿五 13 Sep 25, 2022
Bitburner-bbpm - An experimental package manager for the game Bitburner.

BPPM - BitBurner Package Manager An experimental package manager for the game Bitburner. Install Instructions Download the latest release of bbpm.js.

null 3 Mar 24, 2022
This package includes some opinionated configuration for ESLint.

eslint-config-float This package includes some opinionated configuration for ESLint, used at Float and friends. Installation You can install and use t

Float 2 Jan 7, 2022