Giter Club home page Giter Club logo

true's Issues

Emphasize importance in FP

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.

improve performance

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

Add Typescript support

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.

true is not always true

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.

too complicated

Although this module is admirably simple,
it can be simplified even further:

module.exports = true

Although, this would be a breaking change.

"true" should not be hardcoded

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)?

Add `false` option

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.

Add caching

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?

Move false to variable to improve performance and use true-value library

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.