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

extension-type

v0.0.3

Published

extension type

Downloads

1

Readme

ExtensionType

Typescript扩展类型, 提供一些方便简单的扩展类型

扩展的类型

  • ListMap - Array和Map的混合数组
  • 经纬度坐标
  • XY二维坐标
  • XYZ三维坐标

如何使用

ListMultiMap

ListMap方便在一个Array中再根据属性进行HashMap多重索引.
常见的例子: 在一场游戏中, 玩家存在于一个Array中,
但是有的时候又需要通过 id 来索引用户, 有的时候又要根据座位号 seat 索引. 来看看 ListMultiMap 的处理方式吧

class User {
    uid: string
    seat: number

    constructor(uid: string, seat: number) {
        this.uid = uid;
        this.seat = seat;
    }
}

const user1 = new User("A", 1)
const user2 = new User("B", 2)
const user3 = new User("C", 3)


import ListMultiMap from "extension-type/lib/types/ListMultiMap";

// 你可以通过两种方式来生命一个ListMap,

// 1. 通过数组直接创建
ListMultiMap.from([user1, user2, user3], ["uid", "seat"])
// 2. 创建一个空的 ListMultiMap, 然后增加
let listMultiMap = new ListMultiMap<User>(["uid", "seat"]);
listMultiMap.push(user1)
listMultiMap.push(user2)
listMultiMap.push(user3)


// 获取数组索引获取玩家对象
listMultiMap.getFromList(0) // user1 实例 uid:A, seat: 1

// 通过uid索引玩家对象
listMultiMap.getFromMap("uid", "A"); // user1 实例  uid:A, seat: 1
// 通过座位号索引玩家对象
listMultiMap.getFromMap("seat", 1); // user1 实例  uid:A, seat: 1

// 判断是否存在
listMultiMap.hasFromMap("uid", "A"); // true
listMultiMap.hasFromMap("seat", 1); // true
listMultiMap.hasFromMap("seat", 4); // false



// Object.keys
listMultiMap.getMapKeys("uid") // [A,B,C]
listMultiMap.getMapKeys("seat") // [1,2,3]

// 从数据中移除
listMultiMap.delete(user1) // 将会删除user1
listMultiMap.deleteIndex(0) // (0是数组的索引) 将会删除user1
listMultiMap.deleteKey("uid", "A") // 将会删除user1
listMultiMap.deleteKey("seat", 1) // 将会删除user1

// 同时你还可以使用很多Array的方法
listMultiMap.map(()=>{})
listMultiMap.forEach(()=>{})
listMultiMap.reverse()
listMultiMap.find(()=>{})
listMultiMap.findIndex(()=>{})
// ... 等等

ListMap

ListMap 是一个简化版本的 ListMultiMap, 只能进行一种索引

常见的例子: 在一场游戏中, 玩家存在于一个Array中, 但是有的时候又需要通过 id 来索引用户,来看看ListMap如何使用

class User {
    uid: string
    seat: number

    constructor(uid: string, seat: number) {
        this.uid = uid;
        this.seat = seat;
    }
}

const user1 = new User("A", 1)
const user2 = new User("B", 2)
const user3 = new User("C", 3)


import ListMap from "extension-type/lib/types/ListMap";

// 你可以通过两种方式来生命一个ListMap,

// 1. 通过数组直接创建
ListMap.from([user1, user2, user3], "uid")
// 2. 创建一个空的 ListMap, 然后增加
let listMap = new ListMap<User>("uid");
listMap.push(user1)
listMap.push(user2)
listMap.push(user3)

// list Map 直接继承于 ListMultiMap 可以使用 ListMultiMap 的所有方法
// 但是因为他的特性, 只能单个Map索引, 系统还提供了以下方法
listMap.index(0) // 等同于 ListMultiMap.getFromList 返回 user1 实例 uid:A, seat: 1
listMap.key("A") // 等同于 listMultiMap.getFromMap("uid", "A");  返回 user1 实例 uid:A, seat: 1
listMap.keys() // 等同于 listMultiMap.getMapKeys("uid");  // 返回 [A,B,C]
listMap.has("A") // 等同于 listMultiMap.hasFromMap("uid", "A");  // 返回 true