Socket
Socket
Sign inDemoInstall

props-check

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

props-check - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

lib/error-message.js

10

index.js

@@ -24,7 +24,11 @@ const _ = require('ramda');

PropCheck.human = _.curry((spec, target) => {
return human(spec, PropCheck(spec, target));
});
PropCheck.human = _.curry((spec, target) =>
human(spec, PropCheck(spec, target), null)
);
PropCheck.customHuman = (messages) => _.curry((spec, target) =>
human(spec, PropCheck(spec, target), messages)
);
module.exports = PropCheck;

@@ -1,3 +0,4 @@

_ = require('ramda');
_ = require('ramda');
errorMessage = require('./error-message')

@@ -12,3 +13,10 @@ // type alias Spec =

// type alias CustomMessage =
// { given: [ String ]
// , unexpected: [ String ]
// , missing: [ String ]
// , conclusion: [ String ]
// }
// notNullOrEmpty :: * -> Boolean

@@ -24,18 +32,2 @@ const notNullOrEmpty = _.compose( _.not, _.either( _.isNil, _.isEmpty ) );

// formattedUserInput :: ( Spec, PropCheckResult ) -> String
const formattedUserInput = (spec, result) => {
var keys = [];
for (const key of _.keys(result)) {
keys.push('\n ' + key + ': …');
}
if (_.isEmpty(keys)) return null;
return ' You gave me this:\n\n {'
+ keys.join(',')
+ '\n }';
};
// getPseudoObjectString :: [ Key ] -> String

@@ -63,6 +55,22 @@ const getPseudoObjectString = (keys) => {

// formattedIncorrectInput :: ( Spec, PropCheckResult ) -> String
const formattedIncorrectInput = (spec, result) => {
// formattedUserInput :: ( Spec, PropCheckResult, CustomMessage ) -> String
const formattedUserInput = (spec, result, custom) => {
var keys = [];
for (const key of _.keys(result)) {
keys.push('\n ' + key + ': …');
}
if (_.isEmpty(keys)) return null;
return ' ' + errorMessage(custom).given + '\n\n {'
+ keys.join(',')
+ '\n }';
};
// formattedIncorrectInput
// :: ( Spec, PropCheckResult, CustomMessage ) -> String
const formattedIncorrectInput = (spec, result, custom) => {
return _.compose (
getErrorMessage(' I wasn\'t expecting:\n\n ')
getErrorMessage(' ' + errorMessage(custom).unexpected + '\n\n ')
, getPseudoObjectString

@@ -74,6 +82,7 @@ , _.difference

// formattedExpectedInput :: ( Spec, PropCheckResult ) -> String
const formattedExpectedInput = (spec, result) => {
// formattedExpectedInput
// :: ( Spec, PropCheckResult, CustomMessage ) -> String
const formattedExpectedInput = (spec, result, custom) => {
return _.compose (
getErrorMessage(' You didn\'t give me:\n\n ')
getErrorMessage(' ' + errorMessage(custom).missing + '\n\n ')
, getPseudoObjectString

@@ -85,4 +94,4 @@ , _.difference

// formattedCorrection :: ( Spec, PropCheckResult ) -> String
const formattedCorrection = (spec, result) => {
// formattedCorrection :: ( Spec, PropCheckResult, CustomMessage ) -> String
const formattedCorrection = (spec, result, custom) => {

@@ -100,3 +109,3 @@ var suggested_corrections = [];

return ' You fu*ked up, here\'s how to fix it:\n\n'
return ' ' + errorMessage(custom).conclusion + '\n\n'
+ suggested_corrections.join('\n');

@@ -106,5 +115,12 @@ };

// readableErrorMessage :: ( Spec, PropCheckResult ) -> String
const readableErrorMessage = _.curryN(2, _.compose(
_.join('\n\n')
// wrapString :: String -> String -> String
const wrapString = _.curryN(2, (wrapper, originalString) => {
return wrapper + originalString + wrapper;
});
// readableErrorMessage :: ( Spec, PropCheckResult, CustomMessage ) -> String
const readableErrorMessage = _.curryN(3, _.compose(
wrapString('\n')
, _.join('\n\n')
, _.filter(notNullOrEmpty)

@@ -120,10 +136,10 @@ , _.juxt([

// human :: ( Spec, PropCheckResult ) -> Maybe String
const human = _.curryN(2 , _.ifElse(
nothingIsWrong
// human :: ( Spec, PropCheckResult, CustomMessage ) -> Maybe String
const human = _.ifElse(
_.binary(nothingIsWrong)
, _.always(null)
, readableErrorMessage
));
);
module.exports = human;
{
"name": "props-check",
"version": "0.2.1",
"version": "0.3.0",
"description": "Check your props and give a helpful error if you've mis-typed.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -147,3 +147,3 @@ /*eslint-env node, mocha*/

const result2 = PropCheck.human({ apple: 'String' }, { appel: '' } );
const result2 = PropCheck.human({ apple: 'String' }, { appel: '' });
expect(result2).to.be.a('String');

@@ -155,2 +155,34 @@

describe('::customHuman', () => {
it('should be a function with an arity of 2', () => {
expect(PropCheck.customHuman(null)).to.be.a('function');
expect(PropCheck.customHuman(null).length).to.equal(2);
});
it('should be a curried function', () => {
expect(PropCheck.customHuman(null)).to.be.a('function');
expect(PropCheck.customHuman(null)({})).to.be.a('function');
})
it('should return a string or null if all parameters are provided', () => {
const result1 = PropCheck.customHuman(null)({}, {});
expect(result1).to.be.null;
const result2 =
PropCheck.customHuman(null)({ apple: 'String' }, { appel: '' });
expect(result2).to.be.a('String');
});
});
});

@@ -26,6 +26,6 @@ /*eslint-env node, mocha*/

it('should be a function with an arity of 2', () => {
it('should be a function with an arity of 3', () => {
expect(human).to.be.a('function');
expect(human.length).to.equal(2);
expect(human.length).to.equal(3);

@@ -37,3 +37,3 @@ });

const actual = human(spec, PropCheck(spec, good_test));
const actual = human(spec, PropCheck(spec, good_test), null);

@@ -61,9 +61,9 @@ expect(actual).to.be.null;

const actual1 = human(spec, PropCheck(spec, bad_test1));
const actual1 = human(spec, PropCheck(spec, bad_test1), null);
expect(actual1).to.be.a('String');
const actual2 = human(spec, PropCheck(spec, bad_test2));
const actual2 = human(spec, PropCheck(spec, bad_test2), null);
expect(actual2).to.be.a('String');
const actual3 = human(spec, PropCheck(spec, bad_test3));
const actual3 = human(spec, PropCheck(spec, bad_test3), null);
expect(actual3).to.be.a('String');

@@ -70,0 +70,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