mde / true Goto Github PK
View Code? Open in Web Editor NEWA JavaScript port of the Unix utility 'true'. Returns the Boolean value `true`
A JavaScript port of the Unix utility 'true'. Returns the Boolean value `true`
In functional programming, everything should be a function, because functional programming is about using functions everywhere. If you don’t write functions everywhere you are not a functional programmer. So it is cool that with this module, you can now use a function that returns the value true
, instead of using just the value true
, which is not functional style. As functional programming is all the hype nowadays, I think you should mention this advantage in your docs.
I think the current package became a little to slow. Especially since the caching was removed. Are there any suggestions on how to solve this problem? I was thinking maybe we could write a native c library and then import it to NodeJS if that's possible
For us civilised people who needs both Typescript and the functionality to ensure a value is true, having the ES6 import/export and a boolean type-hint would be a huge boost to my productivity!
I can create a PR to define these, but it could take me months basing on this module's complexity.
I ran into problems when trying to use this module. I added the following code for debugging:
var t = require('true');
var myTrueValue = t();
console.log(myTrueValue === true);
I expected to see the program output true
, but I instead saw false
!
After spending hours tracing the problem down I found that another library was doing the following:
require.cache[require.resolve('true')].exports = function() {
return false;
};
I'm not sure why this particular third party library is doing this, but I feel like something should be done to prevent it since truthiness being correct is very important for any application.
Although this module is admirably simple,
it can be simplified even further:
module.exports = true
Although, this would be a breaking change.
If the ES standard is updated and "true" is changed to another keyword (such as yea, yes, or affirmative) it would break this library. Instead of returning true could we return (1==1)?
Because I see that the package published 7 years ago?
Since this is a port of the unix utility true
, I feel it is important to provide a false
option. Quoting from the man page for GNU true
:
Note, however, that it is possible to cause ‘true’ to exit with
nonzero status: with the ‘--help’ or ‘--version’ option, and with
standard output already closed or redirected to a file that evokes an
I/O error. For example, using a Bourne-compatible shell:
$ ./true --version >&-
./true: write error: Bad file number
$ ./true --version > /dev/full
./true: write error: No space left on device
Clearly we need to provide equivalent functionality in the npm
module.
In most cases, exported function returns same true
value. However, every time we call it, it has to get this value somewhere from engine's depths.
So I decided to do some investigations on how could we optimize performance in V8. Here are the results:
http://jsperf.com/local-true-vs-engine-true
As you can see, we can improve performance by simply caching value of true
in local variable, and performance is critical for such a frequently used function.
Thoughts? Should we use such optimization or are there even better solutions?
the current code is "module.exports = () => true"
It would be better if performance was optimized by moving the true and arrow function to variables.
let True = require('true-value')
then
let t = () => True
and finally
module.exports = t
true-value is a library that will get the value of "true" for you, following the single responsibility principle.
It should be possible to install tool via npm install -g true
and execute it as true
, getting true
right in the console!
Just want to make sure the api is fully covered... https://coveralls.io/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.