Coder Social home page Coder Social logo

ensure's People

Contributors

brentwilton avatar elwynelwyn avatar kristy-j avatar mzoellner avatar phenomnomnominal avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ensure's Issues

isEnum guard does not support string valued enums

If you use a string value enum with the isEnum guard it returns the key name rather than the enum value :(

Maz with Ben

example

enum Foo {
  aaa = 'AAA'
}

let v = isEnum(Foo)('aaa', 'someprop');
assert(v, 'AAA'); // fails as isEnum returns 'aaa'

Support custom "getter" value guards

isNotNull is currently special-cased to only run on get. Can we support marking custom value guard functions to run on get?

An attribute would be petty cool, e.g.

import { Guard } from '@trademe/ensure';

@Guard({ onGet: true })
function myGuard () {
   ...
}

The `isNumber` value guard uses `+` to convert a string to a number

Since the isNumber value guard uses + to convert a string to a number, this has the side-effect of treating a whitespace-only or empty string as zero. E.g. +' ' resolves to 0.

This should probably be treated as an error case. Using parseInt(..., 10) instead should resolve this.

Singleton - Be able to reset properly for unit testing

Can we make the _reset() method differently available, so it's more easily accessible in unit testing?

E.g.: I would like to be able to do something like this:

afterEach(() => {
        // Reset for @Singleton
        let classUnderTest = (<any>CardViewModeService);
        classUnderTest._reset();
    });

But currently, calling TestBed.Get() in afterEach to retrieve it is creating a new instance of the class under test - as I'm unable to reset on the instance.

Craig suggested something more like:

var foo = function singleton() {
        if (!instantiated) {
            checkInjectable(injectable);
            instantiated = true;
            foo._reset = function () { return instantiated = false; };
            return injectable.apply(this, arguments);
        }
        throw new ensure_error_1.EnsureError("\n            " + injectable.name + " is a singleton and must not be instantiated multiple times.\n        ");
    };
    return foo;

Thanks.

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.