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

strikejs-util

v1.1.1

Published

A set of utility classes and functions for web applications.

Downloads

3

Readme

strike-util

A set of utility classes, interfaces, and functions for web applications written in TypeScript.

Interfaces

  • Dictionary

    An interface to provide typings for object literal in TypeScript applications.

    	import {Dictionary} from 'strikejs-util'; 
      	
    	let obj:Dictionary<number> = {
    		"key1":1,
    		"key2":2,
    		"key3":3
    	} 
      	

Functions

1. getDataAt(object,path,sep)

A function that takes an object and return a value from a path within the object.


import {getDataAt} from 'strikejs-util'; 

var obj = {
	name:{
		firstName:"Suhail",
		lastName:"Abood"
	}
}

getDataAt(obj,'name.firstName','.'); //returns "Suhail"

getDataAt(obj,'name/lastName','/'); //returns "Abood" 

2. setDataAt(object,path,newValue,sep)

A function that takes an object and sets a value within the object given a path.


import {setDataAt} from 'strikejs-util'; 

var obj = {
	name:{
		firstName:"Suhail",
		lastName:"Abood"
	}
}; 

setDataAt(obj,'name.firstName','John'); //changes obj.name.firstName = "John"; 

setDataAt(obj,'name/lastName','Doe','/'); //changes obj.name.lastName = "Doe"; 

3. extractArgumentsFromFunction

A function that extracts the names of a function's arguments.


import {extractArgumentsFromFunction} from 'strikejs-util'; 

function myFunction(arg1,arg2,testArg1,testArg2){
	//blah blah blah
}

extractArgumentsFromFunctioN(myFunction); // returns ['arg1','arg2','testArg1','testArg2']

4. curry

A function that supports partial functions execution by currying the function's parameter.


import {curry} from 'strikejs-util'; 

function myFunction(v,w,x,y,z){
	console.log(v,w,x,y,z); 
}

var t = curry(myFunction,1,2,3,4); 

t(5); //logs 1,2,3,4,5 

//or we can do 

var xx = curry(myFunction); 
xx(1,2)
xx(22,33)
x(44); //logs 1 2 22 33 44 

5. identity

A function that returns its first paramters.


import {identity} from 'strikjs-util'; 

identity(100);//returns 100 

6. repeat

A function that repeats a string given number of times.


import {repeat} from 'strikejs-util'; 

repeat("x",10); //xxxxxxxxxx

7. format

A function to format strings using ES6 placeholders.


import {format} from 'strikejs-util'; 

format("This is just a ${placeholder1} and this one is ${placeholder2} another test",{
	placeholder1:"test",
	placeholder2:"yet"
}); //This is just a test and this one is yet another test

8. printf

A C-Style printf function.


import {printf} from 'strikejs-util'; 

printf("My name is %s and I'm %d","Suhail",18); //returns "My name is Suhail and I'm 18"

9. createFormatter

Returns a custom C-style string formatter that can be extended for more formats.


import {createFormatter} from 'strikejs-util'; 

let formatter = createFormatter(); 

formatter.addFormat("upper",function(param){
	return param.toUpperCase();
)}; 

formatter.format("My name is %upper","Suhail"); //returns "My name is SUHAIL" 

10. createPool

Returns a memory pool that can be used to improve memory efficiency


import {createPool} from 'strikejs-util'; 

let pool = createPool(()=>{
	return {
		type:0,
		data:1
	};
}); 

let a = pool.get(); //a = {type:0,data:1}; 
let b = pool.get(); //creates a new object {type:0,data:1}; 
b.data = 2200; 
b.type = 20; 
pool.put(b); 
let c = pool.get(); //returns the item that is currently in the pool {type:20,data:2200};

Polyfills

The library also provides some polyfills taken from the JavaScript community, these are:

1. requestAnimationFramePolyfill

Installs a polyfill for requestAnimationFrame and cancelAnimationFrame.

2. objectAssignPolyfill

Installs a polyfill for Object.assign.