Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@youngbeen/dasmet

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@youngbeen/dasmet

`Dasmet` is a light weight data management(e.g. store, dict) util library

latest
npmnpm
Version
0.1.1
Version published
Weekly downloads
12
Maintainers
1
Weekly downloads
 
Created
Source

[TOC]

Dasmet

Dasmet is a light weight data management(e.g. store, dict) util library

if you hate ugly API usage for plain data store management, you may try dasmet

vuex or other state management systemdata modeldasmet
data init☹️ Complicated🙂 Simple🙂 Simple
accessing data😐 A little complicated🙂 Simple🙂 Simple
setting by k-vMust via commit(maybe complicated)🙂 Simple🙂 Simple
setting by object mergingMust via commit(maybe complicated)❌ No✅ Yes yet simple
data snapshot✅ Yes❌ No❌ No
weight☹️ Heavy🙂 Light🙂 Light
native Array bonus util support❌ No❌ No✅ Yes

Tip: Please note that if you need data snapshot, a state management system is still better solution. But if you are aware of that #YouMayNotNeedStateManagement#, you should avoid using state management system in you project from now.

Features

  • Easy API design as first-class rule
  • Array.get() like map

Install

Install it via npm

npm i -S @youngbeen/dasmet

Import

import { newStore } from '@youngbeen/dasmet'

Usage

Store Usage

// generating data store instance
let userStore = newStore({
  userName: '',
  userId: ''
})

// setting value by k-v
userStore.set('userName', 'you')
userStore.set('newKey', 1)
/* -> {
  userName: 'you',
  userId: '',
  newKey: 1
} 
*/
// setting value by object merging (merge value)
userStore.set({
  userName: 'youngbeen',
  userId: '21'
})
/* -> {
  userName: 'youngbeen',
  userId: '21',
  newKey: 1
} 
*/

// accessing value
userStore.get('userName') // -> 'youngbeen'
// or
userStore.value.userId // -> '21'

Dict Usage

New ES6+ Array has many amazing features like filter, map etc. In a dict model we ofter want to get an item directly, however it is not convenient using dict.someDictTypes.find(item => item.key === targetKey)

Dasmet brings a native support(via Array.prototype) of Array.get method

Array.get(value, [keyName])

e.g.

// finding item by specific value
dict.someDictTypes.get(targetKey)

Meanwhile, you can choose which key to get

dict.someDictTypes.get(targetKey, myKeyName)

Tip: if keyName not set, default get priority is id > key > value

Documents

  • Example of using with vue3

Keywords

data

FAQs

Package last updated on 20 Jan 2021

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