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

ncx-js

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ncx-js

Effortless complex scripts with unlimited power

  • 1.3.4
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ncx

NPM Version NPM License

Effortless complex scripts with unlimited power. Ncx is a JavaScript library for writing complex scripts without complexity that can be used with Node.js

Welcome

Go to Github

Example

Here is a simple example of Ncx use

import { x } from 'ncx-js'

const myScripts = ['echo Hello World!', 'node scripts/hello.js', 'pnpm install', 'tsc']

await x(...myScripts)

API

ncx.x

The commands to be executed are determined by this function. It returns a object with stdout, stderr and error.

import { x } from 'ncx-js'

const data = await x('echo ncx is awesome!')

if (data.error) {
  throw new Error(data.error)
}
ncx.consoleX

The commands to be executed are determined by this function. It returns a object with stdout, stderr and error and prints the output to the console.

import { cx } from 'ncx-js'

const data = await cx('echo ncx is awesome!')

if (data.error) {
  throw new Error(data.error)
}
ncx.beforeAll

The argument function called before all the scripts and commands.

import { x, beforeAll } from 'ncx-js'

beforeAll(() => console.log('Running tests...'))
await x('node scripts/test.js')
ncx.before

The argument function called before scripts and commands.

import { x, before } from 'ncx-js'

before(() => console.log('Running command'))
await x('echo The commmand runned successfully')
ncx.use

The argument function called when scripts and commands executed

import { x, use } from 'ncx-js'

use((out) => {
  if (out.toLowerCase() === 'the command runned successfully') {
    console.log('All done with no errors')
  }

  // Return function handles the error
  // stderr is optional
  return (err, stderr) {
    console.log('All done with error: ' + err)
  }
})
await x('echo The commmand runned successfully')
ncx.after

The argument function called after scripts and commands executed

import { x, after } from 'ncx-js'

after(() => console.log('Runned command'))
await x('echo The commmand runned successfully')
ncx.afterAll

The argument function called after all scripts and commands.

import { x, afterAll } from 'ncx-js'

afterAll(() => console.log('All commands runned'))
await x('echo The commmand runned successfully')

How Ncx Works

Ncx uses globalThis for communication with other functions.

import fs from 'fs'
import path from 'path'
import { x, use, beforeAll } from 'ncx-js'

console.clear()
beforeAll(() => console.log('Running tests...'))

const files = fs.readdirSync(path.join(process.cwd(), 'tests'))

files.forEach(async (file) => {
  await x(`node ./tests/${file}`)
})

For example if we set beforeAll to a function the Ncx changes the globalThis.__ncx_before_all to argument function. With that x function can be use this.

License

MIT

Keywords

FAQs

Package last updated on 22 Jan 2024

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