expandArgs(args) in Nue.js source code.

In this article, we will review a function named expandArgs(args) in Nue.js source code.

To give you some context, this function, expandArgs, is called in another function named getArgs. All these are part of cli.js file in Nue.js source code. Nue.j…


This content originally appeared on DEV Community and was authored by Ramu Narasinga

In this article, we will review a function named expandArgs(args) in Nue.js source code.

Image description

To give you some context, this function, expandArgs, is called in another function named getArgs. All these are part of cli.js file in Nue.js source code. Nue.js a web framework.

expandArgs

// [-npe] --> [-n, -p, -e]
export function expandArgs(args) {
  const arr = []
  args.forEach(arg => {
    if (arg[0] == '-' && arg[1] != '-' && arg[2]) {
      arg.slice(1).split('').forEach(el => arr.push('-' + el))
    } else {
      arr.push(arg)
    }
  })
  return arr
}

You will find this above code in packages/nuekit/src/cli.js. The comment just above this function explains what this function does.

Given an argument -npe , it is converted to [-n, -p, -e] and the check is straight forward too.

if (arg[0] == '-' && arg[1] != '-' && arg[2]) {

and this function is used in getArgs function as shown below:

export function getArgs(argv) {
  const commands = ['serve', 'build', 'init', 'create', 'docs']
  const args = { paths: [], root: null }
  let opt

  expandArgs(argv).forEach((arg) => {
    // skip
    if (arg == '--') {

      // test suite
    } else if (arg.endsWith('.test.js')) {
      args.test = true

About me:

Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

I am open to work on interesting projects. Send me an email at ramu.narasinga@gmail.com

My Github —  https://github.com/ramu-narasinga

My website —  https://ramunarasinga.com

My Youtube channel —  https://www.youtube.com/@ramu-narasinga

Learning platform —  https://thinkthroo.com

Codebase Architecture —  https://app.thinkthroo.com/architecture

Best practices —  https://app.thinkthroo.com/best-practices

Production-grade projects —  https://app.thinkthroo.com/production-grade-projects

References:

  1. https://github.com/nuejs/nue/blob/master/packages/nuekit/src/cli.js#L7

  2. https://github.com/nuejs/nue/blob/master/packages/nuekit/src/cli.js#L25


This content originally appeared on DEV Community and was authored by Ramu Narasinga


Print Share Comment Cite Upload Translate Updates
APA

Ramu Narasinga | Sciencx (2025-04-10T03:30:00+00:00) expandArgs(args) in Nue.js source code.. Retrieved from https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/

MLA
" » expandArgs(args) in Nue.js source code.." Ramu Narasinga | Sciencx - Thursday April 10, 2025, https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/
HARVARD
Ramu Narasinga | Sciencx Thursday April 10, 2025 » expandArgs(args) in Nue.js source code.., viewed ,<https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/>
VANCOUVER
Ramu Narasinga | Sciencx - » expandArgs(args) in Nue.js source code.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/
CHICAGO
" » expandArgs(args) in Nue.js source code.." Ramu Narasinga | Sciencx - Accessed . https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/
IEEE
" » expandArgs(args) in Nue.js source code.." Ramu Narasinga | Sciencx [Online]. Available: https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/. [Accessed: ]
rf:citation
» expandArgs(args) in Nue.js source code. | Ramu Narasinga | Sciencx | https://www.scien.cx/2025/04/10/expandargsargs-in-nue-js-source-code/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.