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

power-helper

v0.7.5

Published

This is javascript tool collection, is your super power helper.

Downloads

307

Readme

Power Helper 是一套整合了多種 JavaScript 工具的輕量化集成工具,它非常簡潔,並且不需要任何依賴項目。這套工具可以被視為一種較為複雜的 Lodash,它可以支援幾乎所有的 JavaScript 環境。

在開發過程中,我們遵照以下幾點讓開發者能夠獲得最佳的開發體驗:

  • 對產品進行了完整的測試覆蓋,確保產品的可靠性。
  • 提供了完善的中文文件支援,以幫助使用者快速上手。
  • 持續改善程式碼品質,確保產品的可維護性和可擴展性。
  • 為編輯器提供了完整的提示,以幫助使用者更高效地進行開發。
  • 提供了完整的 TypeScript 支援,以幫助使用者更好地進行開發。

安裝

npm

npm install power-helper

yarn

yarn add power-helper

如何使用?

PowerHelper 分成三個區塊,相關敘述如下:

Utils

大多由單純的 Function 組成。

calc - 負責計算的單元。

  • toMs - 將指定時間格式的數值轉換成毫秒。

array - 優雅的 Array 操作。

  • check - 如果 Array 沒有指定的值,加入該值,如果有則移除。
  • unique - 移除 Array 中相同的元素。
  • groups - 將 Array 依照指定數量集成一組。
  • asyncMap - 允許非同步進行的 map。
  • randomPick - 從 Array 中隨機獲取一個值。
  • randomPicks - 從 Array 中隨機獲取指定數量且不重複的值,如果指定數量大於 Array 長度時會傳整組 Array。

detect - 驗證當下的執行環境。

  • inAppBrowser - 是否正在 in app browser 裡面執行,很難覆蓋所有應用範圍,僅供參考使用。
  • inMobile - 是否正在 iOS 或是 Android 系統裡面執行。
  • inIOS - 是否正在 iOS 系統裡面執行。
  • inAndroid - 是否正在 Android 系統裡面執行。
  • inSafari - 是否正在 Safari 瀏覽器裡面執行。

flow - 流程控制的工具。

  • run - 直接運行方法並返回結果。
  • sleep - 停止執行指定時間(毫秒)。
  • randomInt - 求整數範圍內的隨機值。
  • createUuid - 建立一組隨機的 v4 uuid。
  • createWithTsUuid - 建立一組隨機的 v4 uuid,但在前面加上當下的 timestamp(ms)。
  • retry - 優雅的設計有限的重複執行直到成功為止。
  • asyncWhile - 結合非同步與計數的迴圈操作。

json - 優雅的 JSON 格式相關處理。

  • jpjs - 經典的深拷貝方案 JSON.parse(JSON.stringify(data))。
  • nonStrictJSONParse - 執行 JSON Parse,如果失敗回傳空白物件 {}
  • nonStrictJSONStringify - 執行 JSON Stringify,如果失敗回傳字串 '{}'

text - 字串相關的處理。

  • headMatch - Text 開頭是否符合目標。
  • lastMatch - Text 結尾是否符合目標。
  • byteLength - 獲取指定 Text 的 Byte 長度。
  • replaceVar - 複寫 Text 的指定變數。
  • format - 轉換 Text 轉換成指定格式,填入 v 代表映射的值。
  • findMatchOrLast - 將指定文字限縮指定字組中,如果都不符合則返回最後一個字組。。

pick - 精準地提取目標相關資源。

  • ifBad - 值如果是 null | undefined | Error | NaN,則回傳預設值。
  • ifEmpty - 值如果是 null | undefined,則回傳預設值。
  • getType - 比 typeof 回傳更精準的類型。
  • peel - 獲取指定路徑的值,如果值不存在回傳 null
  • vars - 獲取文字裡面的變數列表。

checker - 資料檢查器。

  • inputAccept - 負責檢查檔案是否符合 input tag accept 指定的格式。

element - 優雅的 Dom 操作。

  • importScript - 透過執行階段注入 Javascript Tag,這個方法只允許在 Browser 中執行。
  • importCss - 透過執行階段注入帶 stylesheet 的 Link Tag,這個方法只允許在 Browser 中執行。
  • createAndAppend - 新增並將 Tag Append 至指定 Element,這個方法只允許在 Browser 中執行。

record - 優雅的 Object 操作。

  • omit - 淺拷貝同一份 Object,但忽略掉指定對象。
  • simpleCheckDeepDiff - 簡易比對兩個 Object 是否有差異,有差異回傳 true,僅支援 JSON 的所有型態。
  • setMapValue - 複製指定物件的值到目標 Object 上,並產生一份新的 Object。
  • createStrictObject - 建立一組嚴格檢查、轉譯並實質不能變動的 Object,通常應用在環境變數。
  • promiseAllWithKeys - Promise.all 的鍵值對版本。

Modules

更強大的複合工具。

Log - 可以更多變化的 Log。

Hook - 基於非同步架構的事件。

I18n - 多語系操作系統。

Once - 只會執行一次的非同步事件。

Pool - 輕鬆發出請求與快取請求資料的資料池。

Cache - 可以將指定參數請求進行有期限的固定資料存取。

Asset - 資源載入工具,目的是初始化必要的靜態資源。

Event - 簡單的事件監聽器,可以用來監聽和觸發事件。

Timer - 一組計時器,可以正向也可以反向計時。

Ticker - 就如同 setInterval (實際上也是) 一樣運作,只是你可以監聽好幾組事件。

Loader - 可以搜集並發出多個 Promise 的加載元件。

Debounce - 去抖動功能,當觸發事件後會搜集結果並延遲事件發生,避免頻繁發出請求。

Resource - 更優雅的實現獲取各類靜態資源。

Schedule - 可以建立多個定時執行系統,且能保證不重複執行。

Reactive - 透過輪詢的方法監聽物件有沒有發生變動。

JobsQueue - 有限的批次執行作業。

Exception - 高階的錯誤訊息處理工具。

CacheLite - 指定鍵值並同步的存取,非常近似 Map,但是有 TTL。

Breakpoint - 畫面斷點驗證工具。

Interaction - 建立可監聽、追蹤、可搭配視圖化的訊息整合工具。

StyleString - 方便組合出 HTML Element Style 的工具。

LocalStorage - 協助你在複雜的網頁應用程式中更安全的操作 LocalStorage。

AsyncLocalStorage - 非同步的操作 LocalStorage,有助於擴展更多應用模式。

PromiseOverlap - 控制多次發出相同 Promise 時只獲取第一次或是最後一次的結果。

QueryCollection - 一定時間內蒐集資料並統一發出。

WebSocketClient - 具有重新連線與頻道模式的 WebSocket 模塊,你可以透過 onMessage 監聽伺服器方的訊息,並透過 event system 發送給其他監聽對象。

ElementListenerGroup - 將 element 的 addEventListener 昇華到更好操作的階段。

PreloadPort - 可以預先載入資料並透過 id 傳遞給需要的對象。

Types

將複雜的型態方案進行封裝,提高開發的安全性與效率。

date

pick

string

record

import { TDate, TPick, TRecord, TString } from 'power-helper'

Types 只是一種開發 module 時順手的包裝,想要更強大的表達式可以使用以下套件:

utility-types

ts-essentials

Veriosns

0.6.0

  • [新增] - Websocket 新增 keepAlive 保持連線功能。
  • [修正] - 標準化 Event 相關的 Channel 命名。
  • [修正] - job-queues -> jobs-queue。
  • [優化] - 優化文件。

0.7.0

我們對打包形態和文件進行了調整,可以讓整個開發體驗獲得最佳化。

Breaking Changes
  • CacheLite - expTime 參數改為 ttl。
  • Cache - keepAlive 參數改為 ttl。