npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

paptor

v2.0.8

Published

参数适配,解决前后分离项目的接口数据不适用的问题,可以方便的对元数据进行增、删、改

Downloads

3

Readme

param-adaptor

解决前后分离项目的接口数据不适用的问题,可以方便的对元数据进行增、删、改操作。 该项目使用typescript开发,因此推荐使用ts开发

引入

import paptor from 'paptor'

or

<script src='https://unpkg.com/paptor@<version>/dist/paptor.js'></script>

示例

// 包含了两个函数,分别是对对象和数组操作
import { objectAdaptor, arrayAdaptor } from ".."



// define interface
interface IData {
    name: string,
    age: number,
    number: string,
}
// define test date
const data: IData = {
    name: 'Jack',
    age: 20,
    number: '18812345678'
}

// 提取需要的属性 pick prop
console.log(objectAdaptor(data, [['age'], ['number']]));
// { age: 20, number: '18812345678' }

// 提取需求的属性并重命名属性名 pick prop and rename prop
console.log(objectAdaptor(data, [['age', 'Age'], ['number', 'Number']]));
// { Age: 20, Number: '18812345678' }

// 提取需求的属性并修改属性名 pick prop and update value
console.log(objectAdaptor(data, [['age'], ['name', (name) => `name is ${name}`]]));
// { age: 20, name: 'name is Jack' }

// 提取需求的属性、重命名属性名并修改属性名 pick prop, rename prop and update value
console.log(objectAdaptor(data, [['age'], ['name', 'Name', (name) => `name is ${name}`]]));
// { age: 20, Name: 'name is Jack' }

// 过滤属性 filter prop by array
console.log(objectAdaptor(data, [], ['number']));
// { name: 'Jack', age: 20 }

// 使用函数过滤 filter prop by function
console.log(objectAdaptor(data, [], (prop) => prop.startsWith('n')));
// { age: 20 }

// 提取和过滤 pick and filter
console.log(objectAdaptor(data, [['age', 'Age']], ['number']));
// { name: 'Jack', Age: 20 }


// mock list data
const dataList = [
    { name: 'foo', id: '10000001' },
    { name: 'baz', id: '10000002' },
    { name: 'bar', id: '10000003' },
]
// mock tree data
const dataTree = [
    { name: 'foo', id: '10000001' },
    { name: 'baz', id: '10000002', child: [ { name: 'bar', id: '10000003' } ] },
]

// 提取并重命名 pick and rename
console.log(arrayAdaptor(dataList, [['name', 'title'], ['id', 'value']]));
// [ { title: 'foo', value: '10000001' }, { title: 'baz', value: '10000002' }, { title: 'bar', value: '10000003' } ]
console.log(JSON.stringify(arrayAdaptor(dataTree, [['name', 'title'], ['id', 'value']], ['child', 'children'])));
// [{"title":"foo","value":"10000001","children":[]},{"title":"baz","value":"10000002","children":[{"title":"bar","value":"10000003","children":[]}]}]