New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

indicative-utils

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indicative-utils - npm Package Compare versions

Comparing version 7.0.0 to 7.0.1

build/src/cast/index.js

5

build/index.d.ts

@@ -0,4 +1,5 @@

export { cast } from './src/cast';
export { ensureLength } from './src/ensureLength';
export { getValue } from './src/getValue';
export { patchValue } from './src/patchValue';
export { skippable } from './src/skippable';
export { patchValue } from './src/patchValue';
export { cast } from './src/cast';

13

build/index.js

@@ -1,1 +0,12 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["indicative.utils"]=t():e["indicative.utils"]=t()}(this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1);t.ensureLength=r.ensureLength;var o=n(2);t.skippable=o.skippable;var u=n(3);t.patchValue=u.patchValue;var i=n(4);t.cast=i.cast},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ensureLength=function(e,t,n=1){if(e.length<n)throw new Error(t)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.skippable=((e,t,n)=>"arr:literal"!==t&&(n.existyStrict?void 0===e:"string"==typeof e?0===e.trim().length:null==e))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.patchValue=function(e,t,n,r){"arr:literal"!==t?e[t]=n:r.parentArray[r.currentIndex]=n}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=n(5),o=n(6),u=n(7),i=n(8),c=n(9);t.cast=function(e,t,n){if(typeof e===t)return e;let l=null;switch(t){case"number":l=o.toNumber(e);break;case"string":l=u.toString(e);break;case"integer":l=c.toInt(e);break;case"date":l=r.toDate(e);break;case"boolean":l=i.toBoolean(e)}if(!l&&n)throw new Error(n);return l}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toDate=function(e){if(e instanceof Date)return e;if("string"!=typeof e)return null;const t=new Date(e);return"Invalid Date"===t.toString()?null:t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toNumber=function(e){if("number"==typeof e)return e;if("string"!=typeof e)return null;const t=Number(e);return isNaN(t)?null:t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toString=function(e){return null==e||e.constructor===Object?null:String(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=["true","1",1],o=["false","0",0];t.toBoolean=function(e){return"boolean"==typeof e?e:!!r.includes(e)||!o.includes(e)&&null}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.toInt=function(e){if("number"==typeof e)return parseInt(e);if("string"!=typeof e)return null;const t=parseInt(e);return isNaN(t)?null:t}}])});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var cast_1 = require("./src/cast");
exports.cast = cast_1.cast;
var ensureLength_1 = require("./src/ensureLength");
exports.ensureLength = ensureLength_1.ensureLength;
var getValue_1 = require("./src/getValue");
exports.getValue = getValue_1.getValue;
var patchValue_1 = require("./src/patchValue");
exports.patchValue = patchValue_1.patchValue;
var skippable_1 = require("./src/skippable");
exports.skippable = skippable_1.skippable;

@@ -1,5 +0,10 @@

export declare function cast(value: any, toType: 'number', errorMessage?: string): number | null;
export declare function cast(value: any, toType: 'date', errorMessage?: string): Date | null;
export declare function cast(value: any, toType: 'string', errorMessage?: string): string | null;
export declare function cast(value: any, toType: 'integer', errorMessage?: string): number | null;
export declare function cast(value: any, toType: 'boolean', errorMessage?: string): boolean | null;
export declare function cast(value: any, toType: 'float', errorMessage: string): number;
export declare function cast(value: any, toType: 'float'): number | null;
export declare function cast(value: any, toType: 'date', errorMessage: string): Date;
export declare function cast(value: any, toType: 'date'): Date | null;
export declare function cast(value: any, toType: 'string', errorMessage: string): string;
export declare function cast(value: any, toType: 'string'): string | null;
export declare function cast(value: any, toType: 'integer', errorMessage: string): number;
export declare function cast(value: any, toType: 'integer'): number | null;
export declare function cast(value: any, toType: 'boolean', errorMessage: string): boolean;
export declare function cast(value: any, toType: 'boolean'): boolean | null;

@@ -1,1 +0,1 @@

export declare function toInt(value: any): number | null;
export declare function toInt(value: any, fractional?: boolean): number | null;

@@ -1,4 +0,2 @@

export declare function patchValue(data: any, field: string, fieldValue: any, root: {
currentIndex?: number;
parentArray?: any[];
}): void;
import { ValidationDataRoot } from './contracts';
export declare function patchValue(data: ValidationDataRoot, field: string, fieldValue: any): void;
# The MIT License
Copyright 2018 thetutlage, contributors
Copyright 2019 Harminder virk, contributors

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "indicative-utils",
"version": "7.0.0",
"description": "Utilities used by other Indicative packages",
"version": "7.0.1",
"description": "Reusable utilities for indicative validation library",
"main": "build/index.js",
"files": [
"build/src",
"build/index.js",
"build/index.d.ts"
"build/index.d.ts",
"build/index.js"
],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "nyc node japaFile.js",
"test": "node japaFile.js",
"lint": "tslint --project tsconfig.json",
"clean": "del build",
"compile": "npm run lint && npm run clean && webpack",
"build": "npm run compile",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile && typedoc --theme markdown --mdHideSources --excludePrivate && git add docs",
"commit": "git-cz",
"release": "np",
"version": "npm run build"
},

@@ -24,9 +27,23 @@ "keywords": [

],
"author": "virk",
"homepage": "https://indicative.adonisjs.com",
"repository": {
"type": "git",
"url": "git+https://github.com/poppinss/indicative/tree/master/packages/utils.git"
"author": "virk,poppinss",
"license": "MIT",
"devDependencies": {
"@adonisjs/mrm-preset": "^2.0.3",
"@types/node": "^12.0.12",
"commitizen": "^3.1.1",
"cz-conventional-changelog": "^2.1.0",
"del-cli": "^2.0.0",
"doctoc": "^1.4.0",
"husky": "^3.0.0",
"japa": "^2.0.10",
"mrm": "^1.2.2",
"np": "^5.0.3",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint-eslint-rules": "^5.4.0",
"typedoc": "^0.14.2",
"typedoc-plugin-external-module-name": "^2.1.0",
"typedoc-plugin-markdown": "^2.0.8",
"typescript": "^3.5.2"
},
"license": "MIT",
"nyc": {

@@ -40,10 +57,24 @@ "exclude": [

},
"husky": {
"hooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md",
"commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"
}
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"np": {
"contents": ".",
"anyBranch": false
},
"dependencies": {
"lodash.get": "^4.4.2"
},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"bugs": {
"url": "https://github.com/poppinss/indicative/issues"
},
"gitHead": "ec4b9e65401b74657beab116d08dfb8f8b109551"
}
}

@@ -1,90 +0,59 @@

<p align="center">
<a href="#">
<img src="https://res.cloudinary.com/adonisjs/image/upload/v1553759989/indicative-banner_lh27zs.png" width="600px;" />
</a>
</p>
<div align="center">
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1557762307/poppinss_iftxlt.jpg" width="600px">
</div>
<p align="center">
<a href="https://indicative.adonisjs.com/quick-start">Usage</a> •
<a href="https://indicative.adonisjs.com/why">Why?</a> •
<a href="https://indicative.adonisjs.com/features">Features</a> •
<a href="https://indicative.adonisjs.com/examples">Examples</a> •
<a href="https://indicative.adonisjs.com/docs">Documentation</a>
</p>
# Indicative Utils
[![circleci-image]][circleci-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
<br/>
> Collection of utilities used by Indicative packages.
<p align="center">
<a href="https://travis-ci.org/poppinss/indicative">
<img src="https://img.shields.io/travis/poppinss/indicative.svg?style=flat-square" alt="">
</a>
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of contents
<a href="https://www.typescriptlang.org/">
<img src="https://img.shields.io/badge/uses-typescript-blue.svg?style=flat-square" alt="">
</a>
</p>
- [Usage](#usage)
- [API Docs](#api-docs)
- [Maintainers](#maintainers)
## Utils
Handy utility functions used by other Indicative packages. If you are extending Indicative to add your own rules, then you may find some handy utilities in this package.
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Usage
Install the package from npm
Install the package from npm registry as follows:
```sh
npm i indicative-utils
```
and then import the functions you need
```js
import { cast, ensureLength, skippable, patchValue } from 'indicative-utils'
# yarn
yarn add indicative-utils
```
## API
Following is the usage for individual methods
and then use it as follows:
#### `cast(value: any, toType: string, errorMessage?: string): output`
Casts value to a given data type. Returns `null` when unable to cast value.
```js
cast('10', 'number', 'Optional error message to raise exception')
```ts
import {
cast,
ensureLength,
getValue,
patchValue,
skippable
} from 'indicative-utils'
```
- **value**: The value to cast
- **toType**: One of the available types. `'number' | 'date' | 'string' | 'integer' | 'boolean'`
- **errorMessage (optional)**: Raises an exception when `errorMessage` is defined and unable to cast value.
## API Docs
Following are the autogenerated files via Typedoc
---
* [API](docs/README.md)
#### `ensureLength (args: any[], errorMessage: string, minLength = 1): void`
Raise an exception when the length of `args` is less than the defined `minLength`.
## Maintainers
[Harminder virk](https://github.com/thetutlage)
```js
ensureLength(['foo', 'bar'], 'Array must have minimum of 3 items', 3)
```
[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/indicative-utils/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/indicative-utils "circleci"
- **args**: Array to test length
- **errorMessage**: Message for exception, when array length is less than the desired length.
- **minLength (default = 1)**: Minimum desired length.
[npm-image]: https://img.shields.io/npm/v/indicative-utils.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/indicative-utils "npm"
---
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
#### `patchValue (data: any, field: string, fieldValue: any, root: DataRoot)`
This method is used by validation functions that wants to mutate/cast the input value and set it back on the source object. It is recommended to use this method vs doing it manually, since it handles edge cases.
The `DataRoot` value is available inside all validation functions, you must pass it as it is.
```js
patchValue({ age: '10' }, 'age', 10, {})
```
#### `skippable(value: any, fieldName: string, config: { existyStrict: boolean })`
Again, this method is used by validation functions to know if the value of field must be skipped from validation or not.
Indicative by default assumes all fields as optional and one must use `required` rule for required fields. Which means that validation rules like `email`, `date` and so on must skip `undefined` or `null` values based upon the user config. This method does that check for you.
```js
// read field value inside validation function
const fieldValue = data[field]
skippable(fieldValue, field, config)
```
[license-url]: LICENSE.md
[license-image]: https://img.shields.io/aur/license/pac.svg?style=for-the-badge
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