• Stars
    star
    159
  • Rank 227,716 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 1 year ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny 🤏 library (only 410 B) that allows you to access current `<meta>` elements

Current.js

NPM Version NPM Downloads NPM Bundle Size

Introduction

current.js is a tiny 🤏 JavaScript library (only 379 bytes) that allows you to access data stored in "current" HTML <meta> elements.

Installation

To add current.js to your project, run the following command in your terminal:

yarn add current.js

Then, in the JavaScript file where you want to use current.js (usually application.js), add the following line of code:

import "current.js"

This will make the Current object available globally, so you can access it in any file without having to import it again.

Alternatively, you can import the Current object directly:

import { Current } from "current.js"

Usage

To use current.js, you need to add <meta> elements to the <head> section of your HTML document, with the name attribute starting with current-:

<head>
  <meta name="current-environment" content="production">
  <meta name="current-user-id" content="123">
  <meta name="current-user-time-zone-name" content="Central Time (US & Canada)">
</head>

You can then access the data stored in these elements using the Current object. If there is only one <meta> tag with the name you requested, current.js will return the value as a string:

Current.environment
// => "production"

If there are multiple <meta> tags with the same name, current.js will return an object with the remaining name as a camelized key.

Current.user
// => { id: "123", timeZoneName: "Central Time (US & Canada)" }

If the name you requested is not found, it will return an empty object

Current.foo
// => {}

Development

To run the test runner:

yarn install
yarn build
yarn test

Acknowledgments

This library was inspired by the source code of HEY.com, developed by 37signals. The original source code can be found here.

A big shout out to the team at 37signals and HEY.com for not minifying the JavaScript source code in their apps by "Paying tribute to the web with View Source".

We have made some changes and improvements, but this library wouldn't have been possible without their inspiration and ideas. Thanks, it's really appreciated!

More Repositories

1

turbo_power

Power-pack for Turbo Streams
TypeScript
323
star
2

turbo_power-rails

Power-pack for Turbo Streams
Ruby
219
star
3

stimulus-lsp

Intelligent Stimulus tooling for Visual Studio Code and Neovim
TypeScript
127
star
4

gem.sh

Beautiful documentation for any Ruby gem.
Ruby
95
star
5

hotwire.io

Community-driven documentation and resource Hub for Hotwire.
HTML
94
star
6

turbo-morph

Morph action for Turbo Streams
JavaScript
90
star
7

boxdrop

Dropbox Clone built with StimulusReflex
Ruby
76
star
8

formulus

Client-side HTML form validations based on the browser HTML Form Validation API
TypeScript
72
star
9

phlexing

Simple ERB to Phlex converter
Ruby
71
star
10

turbo-ruby

Turbo helpers without the requirement for Rails
Ruby
41
star
11

cable-streams

Extend Turbo Streams with Custom Turbo Stream Actions and CableReady operations
TypeScript
26
star
12

stimulus-parser

Statically analyze Stimulus controllers in your project.
TypeScript
25
star
13

rails7-stimulus-reflex-esbuild

Example StimulusReflex installation using Rails 7 and esbuild
Ruby
24
star
14

stimulus-render

[PoC] HTML rendering mechanism for Stimulus Controllers
TypeScript
18
star
15

type_fusion

Collaborative Ruby type sampling
Ruby
16
star
16

local-time

Modern fork of Basecamp's `local-time`
TypeScript
12
star
17

easy_enum

Turn any Ruby class in an easy to use enum.
Ruby
12
star
18

cable_ready.cr

[WIP] CableReady Crystal port
Crystal
10
star
19

dependabot-bump-together-action

GitHub Action to bump multiple dependencies with dependabot in a single pull request
Ruby
8
star
20

rubocop-stimulus_reflex

Code style checking for StimulusReflex
Ruby
8
star
21

netatmo-ruby

Ruby gem to interact with the Netatmo REST API
Ruby
7
star
22

railsbytes-cli

CLI to apply Railsbytes.com templates to your Rails application
Ruby
7
star
23

cable-streams-rails

Rails companion gem for the `cable-streams` NPM package
Ruby
6
star
24

ShortLook-WhatsApp

Show WhatsApp users' profile pictures in ShortLook when you receive a WhatsApp notification
Objective-C
5
star
25

rubocop-cable_ready

Code style checking for CableReady
Ruby
4
star
26

ShortLook-Bandsintown

Show Bandsintown artists' profile pictures in ShortLook when you receive a Bandsintown notification
Objective-C
4
star
27

shortlook-cli

ShortLook CLI for scaffoling a ShortLook Provider
Ruby
3
star
28

stimulus-blurhash

Stimulus Controller for BlurHash
JavaScript
2
star
29

ShortLook-RocketChat

Show RocketChat users' profile pictures in ShortLook when you receive a RocketChat notification
Objective-C
2
star
30

ShortLook-VK

Show VK users' profile pictures in ShortLook when you receive a VK notification
Objective-C
2
star
31

ShortLook-GitHub

Show GitHub users' profile pictures in ShortLook when you receive a GitHub notification
Objective-C
2
star
32

ShortLook-Line

Show Line users' profile pictures in ShortLook when you receive a Line notification
Objective-C
2
star
33

ShortLook-KakaoTalk

Show KakaoTalk Contact Photos in ShortLook when you receive a KakaoTalk notification
Objective-C
2
star
34

usersnap-stimulus-repro

HTML
1
star
35

rcrdshp-market-extension

Small extension for the RCRDSHP Marketplace
JavaScript
1
star
36

POC2u

Ruby
1
star
37

cable_ready-dsl

[PoC] An opinionated DSL for CableReady.
Ruby
1
star
38

spritpreisrechner-ruby

Ruby Wrapper for the e-control.at Spritpreisrechner HTTP API
Ruby
1
star
39

tankerkoenig-ruby

Ruby Wrapper for the Tankerkoenig API
Ruby
1
star
40

async-websocket-with-inactive-tab

HTML
1
star
41

ShortLook-Mixcloud

Show Mixcloud covers in ShortLook when you receive a Mixcloud notification
Objective-C
1
star
42

stimulus_reflex-form-serialize-app

Ruby
1
star
43

mirrOS_spotify

Modul zum Anzeigen des zurzeit spielenden Track auf Spotify.
PHP
1
star
44

openmensa-parsers

OpenMensa.org parsers
Ruby
1
star
45

ShortLook-LinkedIn

Show LinkedIn users' profile pictures in ShortLook when you receive a LinkedIn notification
Objective-C
1
star
46

ShortLook-Slack

Show Slack users' profile pictures in ShortLook when you receive a Slack notification
Objective-C
1
star
47

ShortLook-SteamChat

Show SteamChat Profile Pictures in ShortLook when you receive a SteamChat notification!
Objective-C
1
star
48

ShortLook-Xing

Show Xing users' profile pictures in ShortLook when you receive a Xing notification
Objective-C
1
star
49

ShortLook-Viber

Show Viber users' profile pictures in ShortLook when you receive a Viber notification
Objective-C
1
star
50

mirrOS_todoist

Dieses mirrOS Modul zeigt deine Aufgaben aus einer Todoist-Liste an.
PHP
1
star