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

fzo

v0.1.3

Published

fzo is simply freeze object library

Downloads

9

Readme

fzo

motivation

const num = 42;
num = 72; // error! ok

const str = 'string';
str = 'str'; // error! ok

const arr = [1, 2, 3, 4, 5];
arr = [4, 4, 2]; // error! ok

arr[0] = 42;
// arr[0] is 1? 42?
console.log(arr[0]); // 42 wow...

arr[72] = 72;
console.log(arr[72]); // 72
console.log(arr); // 42, 2, 3, 4, 5, ...null..., 72 wow...

const obj = {
  kugimiya: 'rie',
  murakawa: 'rie',
  takahashi: 'rie',
  tanaka: 'minami',
};

// hmmm...
obj.tanaka = 'rie';

// obj.tanaka is "manami"? "rie?"
console.log(obj.tanaka); // "rie" wow...

obj.kanda = 'rie';
console.log(obj.kanda); // "rie"

// const is not readonly? :<

I have come to realize a strange truth.

But we can freeze Objects and Arrays using Object.freeze()

const arr = [1, 2, 3, 4, 5];
Object.freeze(arr);

arr[0] = 42;
arr[72] = 74;

console.log(arr); // [1, 2, 3, 4, 5] nice :)

const obj = {
  kugimiya: 'rie',
  murakawa: 'rie',
  takahashi: 'rie',
  tanaka: 'minami',
};
Object.freeze(obj);
obj.kanda = 'rie';

console.log(obj);
// { kugimiya:"rie", murakawa:"rie", takahashi:"rie", tanaka:"minami" } nice :)

// is perfect?

const formation = [
  [4, 4, 2],
  [3, 4, 3],
  [3, 5, 2],
  [5, 5, 0],
  {
    classic: {
      wm: '3-2-2-3',
    },
  },
];

Object.freeze(formation);
formation[0] = [4, 5, 1];
console.log(formation[0]); // [4, 4, 2] nice :?

formation[3512] = [3, 5, 1, 2];
console.log(formation); // immutable :)

formation[0][1] = 5;
formation[0][2] = 1;
console.log(formation[0]); // [4, 5, 1] wow...

formation[4].modern = { Lavolpiana: '3-2-2-3' };
console.log(formation[4]);

// { classic: { "wm": "3-2-2-3" }, modern: {  "Lavolpiana": "3-2-2-3" }} wow...

const voiceActor = {
  minami: 'tanaka',
  rie: {
    kugimiya: 'rie',
    murakawa: 'rie',
    takahashi: 'rie',
    tanaka: 'rie',
  },
};
Object.freeze(voiceActor);

voiceActor.minami = 'tsuda';
console.log(voiceActor.minami); // "tanaka" nice :?

voiceActor.rie.tanaka = 'minami';
console.log(voiceActor.rie.tanaka); // "minami" is not "rie" wow... :<

And there is something strange about DeepClone, the popular and easy way to do it.

const arr = [1, 2, 3, 4, 5];
const newArr = [...arr];

arr.push(42);

console.log(arr); // [1, 2, 3, 4, 5, 42]
conosle.log(newArr); // [1, 2, 3, 4, 5]
// ok :)
const arr = [[1, 2, 3, 4], 5, 6, 7, 8, 9];
const newArr = [...arr];

arr[0].push(42);

console.log(arr); // [[1, 2, 3, 4, 42], 5, 6, 7, 8, 9]
console.log(newArr); // [[1, 2, 3, 4, 42], 5, 6, 7, 8, 9] wow... :<

We all like "pure," but the truth, world is not pure.

But we must aspire to the maximum of purity.

So, let's go on a journey for "pure".

Installation

browser

<script src="https://cdn.jsdelivr.net/npm/fzo@latest"></script>

npm & node.js

npm i fzo
const arr = [1, 2, 3, [4, 5, 6, 7]];
const _ = require('fzo');

const frozenArr = _.fzo(arr);
const deepCloneArr = _.deepClone(arr);
const frozenDeepCloneArr = _.fzo(_.deepClone(arr));
const arr = [1, 2, 3, [4, 5, 6, 7]];
const { fzo, deepClone } = require('fzo');

const frozenArr = fzo(arr);
const deepCloneArr = deepClone(arr);
const frozenDeepCloneArr = fzo(deepClone(arr));

License

Apache 2.0