Socket
Book a DemoInstallSign in
Socket

@g2crowd/extract-options

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@g2crowd/extract-options

Pull namespaced options out of a hash

1.3.1
latest
Source
npmnpm
Version published
Maintainers
4
Created
Source

extract-options

This package is responsible for extracting a subset of a hash, based on a namespaced key.

It is useful for reading options out of DOM data attributes, where there may be multiple keys with different concerns.

Installation

npm install @g2crowd/extract-options --save

Usage

This will create a new hash, seperating out keys based on a common prefix:

import { extractOptions } from '@g2crowd/extract-options';
const startingHash = { prefixOne: 1, prefixTwo: 2, otherKey: 3 };

extractOptions(startingHash, 'prefix'); //=> { one: 1, two: 2 }

It will treat keys with an Options suffix as special. It will expect a hash of raw options to follow:

const startingHash = { prefixOne: 1, prefixTwo: 2, otherKey: 3, prefixOptions: { three: 3 } };

extractOptions(startingHash, 'prefix'); //=> { one: 1, two: 2, three: 3 }

Pairs nicely with jQuery.data:

<div id="element" data-prefix-one="1" data-prefix-two="2" data-other-key="3"></div>
let data = $('#element').data();
const options = extractOptions(data, 'prefix'); //=> { one: 1, two: 2 }

FAQs

Package last updated on 27 Aug 2023

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.