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

smart-preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smart-preprocessor - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

4

bdd-spec.md

@@ -427,7 +427,7 @@ # TOC

var check = function( fcode , op , rightValue , switchs , expected ) {
var check = function( fcode , op , rightValue , switches , expected ) {
var code = string.format( fcode , op , rightValue ) ;
expect( spp.preprocess( code , switchs ) ).to.be( expected ) ;
expect( spp.preprocess( code , switches ) ).to.be( expected ) ;
} ;

@@ -434,0 +434,0 @@

@@ -13,18 +13,18 @@

Smart Preprocessor allows you to preprocess a Javascript module, to build modified versions or even load at run-time
(*require()*) a modified version of the code.
Smart Preprocessor allows you to preprocess a Javascript module, to build modified versions of the module,
or even load a modified version of the module at run-time (*require()*).
While it is inspired by the C/C++ preprocessor, the syntax is different in order to be in phase with the Javascript's spirit.
While it is inspired by the C/C++ preprocessor, the syntax is different to be more in phase with the Javascript's spirit.
Its syntax is hidden behind the comment mark, so the original source file is
[perfectly operationnal without any pre-processing](#recommandations)
[perfectly operational without any pre-processing](#recommendations)
Common use cases:
##### Common use cases:
* you want a lot of logs in development mode, but you don't even want that the production code had to filter out
them with dozens of *if* statement.
* you want a lot of logs in development mode, but you don't even want that the production code had to filter them out
with dozens of *if* statements.
* your source code use specific feature of an engine, namely *io.js*, but you have specified an alternative code
* your source code uses specific features of an engine, namely *io.js*, but you have specified an alternative code
that is compatible with *node.js*.

@@ -34,3 +34,3 @@

Be sure to check the [recommandations](#recommandations).
Be sure to check the [recommendations](#recommendations).

@@ -47,8 +47,9 @@

`smart-preprocessor <source-file> [dest-file] [--switch1 value1] [--switch2 value2] [...]`.
`smart-preprocessor <source-file> [dest-file] [--switch1 [value1]] [--switch2 [value2]] [...]`.
If *dest* is not passed, the standard output will be assumed. It's useful if we have to pipe to another program.
If *dest* is not given, the standard output will be assumed. It's useful if we have to pipe that into another program.
All the *switch* are identifiers we have used in our source-file. See below.
Any alpha-numric string can be used as a switch.
All *switches* are identifiers we have used in our source-file. See below.
Any alpha-numric string can be used as a *switch*.
Just try to be consistent with other projects.

@@ -58,4 +59,4 @@

* `smart-preprocessor main.js main.debug.js --debug`: build the main.debug.js file from main.js, using the *debug* parameter
* `smart-preprocessor main.js main.trace.js --loglevel trace`: build the main.trace.js file from main.js,
* `smart-preprocessor main.js main.debug.js --debug`: build the *main.debug.js* file from *main.js*, using the *debug* parameter
* `smart-preprocessor main.js main.trace.js --loglevel trace`: build the *main.trace.js* file from *main.js*,
setting the *loglevel* parameter to 'trace'

@@ -71,10 +72,10 @@

### .require( module , switchs , [ options ] )
### .require( module , switches , [ options ] )
* module: `string` the module to load
* switchs: `object` an object containing the preprocessor switchs
* options: `object` *optional*, contains some options where:
* multi: if the module is required multiple times with different *switchs* objects, multiple
* switches: `object` an object containing the preprocessor switches
* options: `object` *optional*, contains some options, available options are:
* multi: if the module is required multiple times with different *switches* objects, multiple
instances of the module will be spawned. Without this options, subsequent *require* will use the first
instance even if the *switchs* object are different. Some node.js module execute code
instance even if the *switches* object is different. Some node.js module execute code
at require-time, that's why the default behaviour is to share only one instance, just like a normal

@@ -89,12 +90,12 @@ *require()* does.

When loading a module not lying in a `node_modules` directory, you must provide the full path of the file,
one may simply prepend `__dirname` to the path's string.
When loading a module that is not lying in a `node_modules` directory, you must provide the full path of the file.
One may simply prepend `__dirname` to the path string.
<a name="recommandations"></a>
## Recommandations / Good practices
<a name="recommendations"></a>
## Recommendations / Good practices
* Your source code should be working without any preprocessing, that's what make
[Preprocessor.js](http://npmjs.org/package/preprocessor) a bad thing, Javascript must run unprocessed.
* Your source code should be working without any preprocessing. That's what make
[Preprocessor.js](http://npmjs.org/package/preprocessor) a bad thing, Javascript must run unprocessed, out of the box.
* In fact, your source code should be your standard / production version

@@ -117,3 +118,3 @@ * Use runtime preprocessor's *.require()* only for development, debugging, or any kind of fail-safe or emergency mode,

In fact, many command works by commenting or uncommenting lines.
In fact, many commands work by commenting or uncommenting a line or a block.

@@ -124,6 +125,6 @@ A preprocessor command start with a *preprocessor mark*.

For inline command, this will start by `//#` without spaces.
For inline command, this will start with `//#`.
For multi-line command, this will start with either `/*#` or `//*#`, see below the differences.
Multi-line command stop at `//*/`.
Multi-line commands stop at `//*/`.

@@ -136,3 +137,3 @@

If *expression* is truthy, then the code is uncommented.
If *expression* is true, then the code is uncommented.

@@ -155,3 +156,3 @@ Example, source code of *hello.js*:

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -170,3 +171,3 @@ ```js

If *expression* is truthy, then the code is commented.
If *expression* is true, then the code is commented.

@@ -189,3 +190,3 @@ Example, source code of *hello.js*:

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -226,3 +227,3 @@ ```js

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -242,3 +243,3 @@ ```js

If *expression* is truthy, the code is commented.
If *expression* is true, the code is commented.

@@ -267,3 +268,3 @@ Example, source code of *hello.js*:

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -290,3 +291,3 @@ ```js

This is the list of all type comparison.
This is the list of all possible comparisons.

@@ -300,5 +301,5 @@

**Please be extremely careful: unlike Javascript, even if a switch's value is 0, the condition will still be true**.
**Please be extremely careful: unlike Javascript, even if a switch's value is 0, the condition will still hold true**.
**This expression does not check if the switch is truthy or falsy, it checks if it exists.**
Also there are [strong rationals behind this design)(#recommandations).
There are [strong rationales behind this design](#recommendations).

@@ -311,4 +312,6 @@ Example:

If a *debug* switch exists, whatever its value, then the code will be uncommented.
#### `<switch> = <value>`

@@ -324,3 +327,3 @@

If a switch *loglevel* exists and is set to "trace", then the code is uncommented.
If a *loglevel* switch exists and is set to "trace", then the code will be uncommented.

@@ -340,3 +343,3 @@

If a switch *loglevel* exists, is a number and is greater than or equals to 3, then the code is uncommented.
If a *loglevel* switch exists, is a number and is greater than or equal to 3, then the code will be uncommented.

@@ -350,3 +353,3 @@

When an expression involve a switch that has aliases, the preprocessor will try to perform alias substitution on
When an expression involves a switch that has aliases, the preprocessor will try to perform *alias substitution* on
both the switch's value and the value against whom the switch is compared.

@@ -370,3 +373,3 @@

Then we have a conditional syntax, comparing against *warning*... *warning* is replaced by *1* beforehand.
Therefore, if the *loglevel* switch is *warning*, *verbose*, *trace* or any number greater than or equals to 3,
Therefore, if the *loglevel* switch is *warning*, *verbose*, *trace* or any number greater than or equal to 3,
the code will be uncommented.

@@ -376,5 +379,5 @@

* it can be thought as defining a constant
* it can be thought as defining an enum
* it can be used to perform *greater than* or *lesser than* comparison with strings
* it can be thought as a constant
* it can be thought as an enum
* it can be used to perform *greater than* or *lesser than* comparisons between strings

@@ -403,3 +406,3 @@

If you had typed `smart-preprocessor code.js code.pproc.js --loglevel warning`, *code.pproc.js* would be:
If you had typed `smart-preprocessor code.js code.pproc.js --loglevel warning`, *code.pproc.js* would had been:

@@ -411,3 +414,3 @@ ```js

If you had typed `smart-preprocessor code.js code.pproc.js --loglevel`, *code.pproc.js* would be:
If you had typed `smart-preprocessor code.js code.pproc.js --loglevel`, *code.pproc.js* would had been:

@@ -420,4 +423,4 @@ ```js

Please note that if the *loglevel* switch wasn't defined, the whole line would be blank.
This is still related to the fact that [*no switch = original unprocessed source code*](#recommandations).
So if you had typed `smart-preprocessor code.js code.pproc.js --whatever`, *code.pproc.js* would be:
This is still related to the fact that [*no switch = original unprocessed source code*](#recommendations).
So if you had typed `smart-preprocessor code.js code.pproc.js --whatever`, *code.pproc.js* would had been:

@@ -431,4 +434,4 @@ ```js

* object: `//# loglevel -> myObject.child.prop` -> `myObject.child.prop = 'warning' ;`
* array: `//# loglevel -> myArray[ 5 ]` -> `myArray[ 5 ] = 'warning' ;`
* object: `//# loglevel -> myObject.child.prop` becomes `myObject.child.prop = 'warning' ;`
* array: `//# loglevel -> myArray[ 5 ]` becomes `myArray[ 5 ] = 'warning' ;`

@@ -446,3 +449,3 @@

... will assign the *loglevel* switch to *myVar* only if loglevel === trace.
... will assign the *loglevel* switch to *myVar* only if *loglevel === trace*.

@@ -455,3 +458,3 @@ Another example:

... will assign the *loglevel* switch to *myVar* only if loglevel is a number and is greater than or equals to 3.
... will assign the *loglevel* switch to *myVar* only if *loglevel* is a number and is greater than or equal to 3.

@@ -473,7 +476,7 @@

**However spaces between the comment mark ('//' or '/*') and the '#' are \*NOT\* allowed!**
**However spaces between the comment mark ('//', '/\*' or '//\*') and the '#' are \*NOT\* allowed!**
This is called *the preprocessor mark*.
This is called *the preprocessor mark*, and therefore should be preserved.
Therefore, the current code has no effect:
Thus the current code has no effect:
```js

@@ -480,0 +483,0 @@ // # debug : console.log( 'Warning!' ) ;

{
"name": "smart-preprocessor",
"version": "0.1.1",
"version": "0.1.2",
"description": "A smart preprocessor for Node.",

@@ -5,0 +5,0 @@ "main": "lib/smartPreprocessor.js",

@@ -13,18 +13,18 @@

Smart Preprocessor allows you to preprocess a Javascript module, to build modified versions or even load at run-time
(*require()*) a modified version of the code.
Smart Preprocessor allows you to preprocess a Javascript module, to build modified versions of the module,
or even load a modified version of the module at run-time (*require()*).
While it is inspired by the C/C++ preprocessor, the syntax is different in order to be in phase with the Javascript's spirit.
While it is inspired by the C/C++ preprocessor, the syntax is different to be more in phase with the Javascript's spirit.
Its syntax is hidden behind the comment mark, so the original source file is
[perfectly operationnal without any pre-processing](#recommandations)
[perfectly operational without any pre-processing](#recommendations)
Common use cases:
##### Common use cases:
* you want a lot of logs in development mode, but you don't even want that the production code had to filter out
them with dozens of *if* statement.
* you want a lot of logs in development mode, but you don't even want that the production code had to filter them out
with dozens of *if* statements.
* your source code use specific feature of an engine, namely *io.js*, but you have specified an alternative code
* your source code uses specific features of an engine, namely *io.js*, but you have specified an alternative code
that is compatible with *node.js*.

@@ -34,3 +34,3 @@

Be sure to check the [recommandations](#recommandations).
Be sure to check the [recommendations](#recommendations).

@@ -47,8 +47,9 @@

`smart-preprocessor <source-file> [dest-file] [--switch1 value1] [--switch2 value2] [...]`.
`smart-preprocessor <source-file> [dest-file] [--switch1 [value1]] [--switch2 [value2]] [...]`.
If *dest* is not passed, the standard output will be assumed. It's useful if we have to pipe to another program.
If *dest* is not given, the standard output will be assumed. It's useful if we have to pipe that into another program.
All the *switch* are identifiers we have used in our source-file. See below.
Any alpha-numric string can be used as a switch.
All *switches* are identifiers we have used in our source-file. See below.
Any alpha-numric string can be used as a *switch*.
Just try to be consistent with other projects.

@@ -58,4 +59,4 @@

* `smart-preprocessor main.js main.debug.js --debug`: build the main.debug.js file from main.js, using the *debug* parameter
* `smart-preprocessor main.js main.trace.js --loglevel trace`: build the main.trace.js file from main.js,
* `smart-preprocessor main.js main.debug.js --debug`: build the *main.debug.js* file from *main.js*, using the *debug* parameter
* `smart-preprocessor main.js main.trace.js --loglevel trace`: build the *main.trace.js* file from *main.js*,
setting the *loglevel* parameter to 'trace'

@@ -71,10 +72,10 @@

### .require( module , switchs , [ options ] )
### .require( module , switches , [ options ] )
* module: `string` the module to load
* switchs: `object` an object containing the preprocessor switchs
* options: `object` *optional*, contains some options where:
* multi: if the module is required multiple times with different *switchs* objects, multiple
* switches: `object` an object containing the preprocessor switches
* options: `object` *optional*, contains some options, available options are:
* multi: if the module is required multiple times with different *switches* objects, multiple
instances of the module will be spawned. Without this options, subsequent *require* will use the first
instance even if the *switchs* object are different. Some node.js module execute code
instance even if the *switches* object is different. Some node.js module execute code
at require-time, that's why the default behaviour is to share only one instance, just like a normal

@@ -89,12 +90,12 @@ *require()* does.

When loading a module not lying in a `node_modules` directory, you must provide the full path of the file,
one may simply prepend `__dirname` to the path's string.
When loading a module that is not lying in a `node_modules` directory, you must provide the full path of the file.
One may simply prepend `__dirname` to the path string.
<a name="recommandations"></a>
## Recommandations / Good practices
<a name="recommendations"></a>
## Recommendations / Good practices
* Your source code should be working without any preprocessing, that's what make
[Preprocessor.js](http://npmjs.org/package/preprocessor) a bad thing, Javascript must run unprocessed.
* Your source code should be working without any preprocessing. That's what make
[Preprocessor.js](http://npmjs.org/package/preprocessor) a bad thing, Javascript must run unprocessed, out of the box.
* In fact, your source code should be your standard / production version

@@ -117,3 +118,3 @@ * Use runtime preprocessor's *.require()* only for development, debugging, or any kind of fail-safe or emergency mode,

In fact, many command works by commenting or uncommenting lines.
In fact, many commands work by commenting or uncommenting a line or a block.

@@ -124,6 +125,6 @@ A preprocessor command start with a *preprocessor mark*.

For inline command, this will start by `//#` without spaces.
For inline command, this will start with `//#`.
For multi-line command, this will start with either `/*#` or `//*#`, see below the differences.
Multi-line command stop at `//*/`.
Multi-line commands stop at `//*/`.

@@ -136,3 +137,3 @@

If *expression* is truthy, then the code is uncommented.
If *expression* is true, then the code is uncommented.

@@ -155,3 +156,3 @@ Example, source code of *hello.js*:

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -170,3 +171,3 @@ ```js

If *expression* is truthy, then the code is commented.
If *expression* is true, then the code is commented.

@@ -189,3 +190,3 @@ Example, source code of *hello.js*:

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -226,3 +227,3 @@ ```js

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -242,3 +243,3 @@ ```js

If *expression* is truthy, the code is commented.
If *expression* is true, the code is commented.

@@ -267,3 +268,3 @@ Example, source code of *hello.js*:

If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would be:
If you had typed `smart-preprocessor hello.js hello.pproc.js --whatever`, *hello.pproc.js* would had been:

@@ -290,3 +291,3 @@ ```js

This is the list of all type comparison.
This is the list of all possible comparisons.

@@ -300,5 +301,5 @@

**Please be extremely careful: unlike Javascript, even if a switch's value is 0, the condition will still be true**.
**Please be extremely careful: unlike Javascript, even if a switch's value is 0, the condition will still hold true**.
**This expression does not check if the switch is truthy or falsy, it checks if it exists.**
Also there are [strong rationals behind this design)(#recommandations).
There are [strong rationales behind this design](#recommendations).

@@ -311,4 +312,6 @@ Example:

If a *debug* switch exists, whatever its value, then the code will be uncommented.
#### `<switch> = <value>`

@@ -324,3 +327,3 @@

If a switch *loglevel* exists and is set to "trace", then the code is uncommented.
If a *loglevel* switch exists and is set to "trace", then the code will be uncommented.

@@ -340,3 +343,3 @@

If a switch *loglevel* exists, is a number and is greater than or equals to 3, then the code is uncommented.
If a *loglevel* switch exists, is a number and is greater than or equal to 3, then the code will be uncommented.

@@ -350,3 +353,3 @@

When an expression involve a switch that has aliases, the preprocessor will try to perform alias substitution on
When an expression involves a switch that has aliases, the preprocessor will try to perform *alias substitution* on
both the switch's value and the value against whom the switch is compared.

@@ -370,3 +373,3 @@

Then we have a conditional syntax, comparing against *warning*... *warning* is replaced by *1* beforehand.
Therefore, if the *loglevel* switch is *warning*, *verbose*, *trace* or any number greater than or equals to 3,
Therefore, if the *loglevel* switch is *warning*, *verbose*, *trace* or any number greater than or equal to 3,
the code will be uncommented.

@@ -376,5 +379,5 @@

* it can be thought as defining a constant
* it can be thought as defining an enum
* it can be used to perform *greater than* or *lesser than* comparison with strings
* it can be thought as a constant
* it can be thought as an enum
* it can be used to perform *greater than* or *lesser than* comparisons between strings

@@ -403,3 +406,3 @@

If you had typed `smart-preprocessor code.js code.pproc.js --loglevel warning`, *code.pproc.js* would be:
If you had typed `smart-preprocessor code.js code.pproc.js --loglevel warning`, *code.pproc.js* would had been:

@@ -411,3 +414,3 @@ ```js

If you had typed `smart-preprocessor code.js code.pproc.js --loglevel`, *code.pproc.js* would be:
If you had typed `smart-preprocessor code.js code.pproc.js --loglevel`, *code.pproc.js* would had been:

@@ -420,4 +423,4 @@ ```js

Please note that if the *loglevel* switch wasn't defined, the whole line would be blank.
This is still related to the fact that [*no switch = original unprocessed source code*](#recommandations).
So if you had typed `smart-preprocessor code.js code.pproc.js --whatever`, *code.pproc.js* would be:
This is still related to the fact that [*no switch = original unprocessed source code*](#recommendations).
So if you had typed `smart-preprocessor code.js code.pproc.js --whatever`, *code.pproc.js* would had been:

@@ -431,4 +434,4 @@ ```js

* object: `//# loglevel -> myObject.child.prop` -> `myObject.child.prop = 'warning' ;`
* array: `//# loglevel -> myArray[ 5 ]` -> `myArray[ 5 ] = 'warning' ;`
* object: `//# loglevel -> myObject.child.prop` becomes `myObject.child.prop = 'warning' ;`
* array: `//# loglevel -> myArray[ 5 ]` becomes `myArray[ 5 ] = 'warning' ;`

@@ -446,3 +449,3 @@

... will assign the *loglevel* switch to *myVar* only if loglevel === trace.
... will assign the *loglevel* switch to *myVar* only if *loglevel === trace*.

@@ -455,3 +458,3 @@ Another example:

... will assign the *loglevel* switch to *myVar* only if loglevel is a number and is greater than or equals to 3.
... will assign the *loglevel* switch to *myVar* only if *loglevel* is a number and is greater than or equal to 3.

@@ -473,7 +476,7 @@

**However spaces between the comment mark ('//' or '/*') and the '#' are \*NOT\* allowed!**
**However spaces between the comment mark ('//', '/\*' or '//\*') and the '#' are \*NOT\* allowed!**
This is called *the preprocessor mark*.
This is called *the preprocessor mark*, and therefore should be preserved.
Therefore, the current code has no effect:
Thus the current code has no effect:
```js

@@ -480,0 +483,0 @@ // # debug : console.log( 'Warning!' ) ;

@@ -447,7 +447,7 @@ /*

var check = function( fcode , op , rightValue , switchs , expected ) {
var check = function( fcode , op , rightValue , switches , expected ) {
var code = string.format( fcode , op , rightValue ) ;
expect( spp.preprocess( code , switchs ) ).to.be( expected ) ;
expect( spp.preprocess( code , switches ) ).to.be( expected ) ;
} ;

@@ -454,0 +454,0 @@

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