New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

object-search-key

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-search-key

Match the appropriate search keywords according to the key value definition of the object

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
6
-14.29%
Maintainers
1
Weekly downloads
 
Created
Source

object-search-key

Alita NPM version NPM downloads Build Status Coverage Status License

Match the appropriate search keywords according to the key value definition of the object. Use yaml-joi as validator.

Install

$ npm install object-search-key
or
$ yarn add object-search-key

Example

import { getObjectSearchKeys } from 'object-search-key';

const AccountModelDefine = `
type: object
isSchema: true
limitation:
  - keys:
      id:
        type: number
        isSchema: true
        limitation:
          - min: 0
          - max: 999999999
          - integer: []
      name:
        type: string
        isSchema: true
        limitation:
          - max: 32
      age:
        type: number
        isSchema: true
        limitation:
          - min: 0
          - integer: []
      locked:
        type: string
        isSchema: true
        limitation:
          - only: [Y, N]
`;

const searchInput = '-123 hele xiaohuoni 24 1.2 N'.split(/(?:\s*)/);
const search = getObjectSearchKeys(AccountModelDefine, searchInput);
/**
 * Result:
 * {
 *   id: [24],
 *   name: ['-123', 'hele', 'xiaohuoni', '24', '1.2', 'N'],
 *   age: [24],
 *   locked: ['N'],
 * }
 */
const or = Object.entries(search).reduce((prev, [key, value]) => {
  return prev.concat(value.map(searchKey => ({ [key]: searchKey })));
}, []);

sequelize.Account.findAndCountAll({ where: { [Op.or]: or } });

/**
 * [
 *   { id: '123' },
 *   { id: '24' },
 *   { name: '123' },
 *   { name: 'hele' },
 *   { name: 'xiaohuoni' },
 *   { name: '24' },
 *   { name: '1.2' },
 *   { name: 'N' },
 *   { age: '123' },
 *   { age: '24' },
 *   { locked: 'N' },
 * ]
 */

Get more at cases.yml.

Keywords

key

FAQs

Package last updated on 13 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts