Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lopatnov/namespace

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lopatnov/namespace - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

1

dist/namespace.d.ts
declare type NamespacePath = string | Array<string>;
/** Namespace class */
export default class Namespace {
static attach<T>(to: T): T & Namespace;
constructor(path?: NamespacePath);

@@ -5,0 +6,0 @@ protected init(path: NamespacePath | undefined): void;

@@ -8,2 +8,10 @@ /** Namespace class */

}
Namespace.attach = function (to) {
var names = Object.keys(Namespace.prototype);
for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
var name_1 = names_1[_i];
to[name_1] = Namespace.prototype[name_1];
}
return to;
};
Namespace.prototype.init = function (path) {

@@ -10,0 +18,0 @@ if (this.isValidPath(path)) {

@@ -14,2 +14,10 @@ (function (global, factory) {

}
Namespace.attach = function (to) {
var names = Object.keys(Namespace.prototype);
for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
var name_1 = names_1[_i];
to[name_1] = Namespace.prototype[name_1];
}
return to;
};
Namespace.prototype.init = function (path) {

@@ -16,0 +24,0 @@ if (this.isValidPath(path)) {

2

dist/namespace.min.js

@@ -7,3 +7,3 @@ (function (global, factory) {

var Namespace=function(){function t(e){if(!(this instanceof t))return new t(e);this.init(e);}return t.prototype.init=function(t){if(this.isValidPath(t)){var e=this.parsePath(t),i=e.shift();this.isValidKey(i)&&this.appendChildren(e,i);}},t.prototype.isValidPath=function(t){return "string"==typeof t||Array.isArray(t)&&t.length>0},t.prototype.parsePath=function(t){var e=this;return Array.isArray(t)?t:t.split(this.getSplitter()).filter((function(t){return e.filterName(t)}))},t.prototype.getSplitter=function(){return /[\[\]."']/gi},t.prototype.filterName=function(t){return !!t&&!!t.trim()},t.prototype.isValidKey=function(t){return "string"==typeof t},t.prototype.getNamespaceClass=function(){return this instanceof t?this.constructor:t},t.prototype.take=function(t){var e,i=this.isValidPath(t),r=this,s=void 0,n=!0,a=[];if(i)for(a=this.parsePath(t);a.length>0;){if(!(e=a.shift())||!r[e]){n=!1,s=e?r[e]:void 0;break}r=r[e];}return {last:r,lastName:e,errLast:s,left:a,exists:n,isValidPath:i}},t.prototype.appendChildren=function(t,e){var i=new(this.getNamespaceClass())(t);return i.applyTo(this,e),i},t.prototype.applyTo=function(t,e){if(!this.isValidKey(e))throw new Error("name of context is "+e);t[e]=this;},t.prototype.exists=function(t){return this.take(t).exists},t.prototype.goto=function(t){var e=this.take(t);return e.exists?e.last:e.errLast},t.prototype.namespace=function(t){var e=this.take(t);return e.exists?e.last:this.appendChildren.call(e.last,e.left.slice(),e.lastName).goto(e.left)},t}();
var Namespace=function(){function t(e){if(!(this instanceof t))return new t(e);this.init(e);}return t.attach=function(e){for(var r=0,i=Object.keys(t.prototype);r<i.length;r++){var n=i[r];e[n]=t.prototype[n];}return e},t.prototype.init=function(t){if(this.isValidPath(t)){var e=this.parsePath(t),r=e.shift();this.isValidKey(r)&&this.appendChildren(e,r);}},t.prototype.isValidPath=function(t){return "string"==typeof t||Array.isArray(t)&&t.length>0},t.prototype.parsePath=function(t){var e=this;return Array.isArray(t)?t:t.split(this.getSplitter()).filter((function(t){return e.filterName(t)}))},t.prototype.getSplitter=function(){return /[\[\]."']/gi},t.prototype.filterName=function(t){return !!t&&!!t.trim()},t.prototype.isValidKey=function(t){return "string"==typeof t},t.prototype.getNamespaceClass=function(){return this instanceof t?this.constructor:t},t.prototype.take=function(t){var e,r=this.isValidPath(t),i=this,n=void 0,a=!0,s=[];if(r)for(s=this.parsePath(t);s.length>0;){if(!(e=s.shift())||!i[e]){a=!1,n=e?i[e]:void 0;break}i=i[e];}return {last:i,lastName:e,errLast:n,left:s,exists:a,isValidPath:r}},t.prototype.appendChildren=function(t,e){var r=new(this.getNamespaceClass())(t);return r.applyTo(this,e),r},t.prototype.applyTo=function(t,e){if(!this.isValidKey(e))throw new Error("name of context is "+e);t[e]=this;},t.prototype.exists=function(t){return this.take(t).exists},t.prototype.goto=function(t){var e=this.take(t);return e.exists?e.last:e.errLast},t.prototype.namespace=function(t){var e=this.take(t);return e.exists?e.last:this.appendChildren.call(e.last,e.left.slice(),e.lastName).goto(e.left)},t}();

@@ -10,0 +10,0 @@ return Namespace;

{
"name": "@lopatnov/namespace",
"version": "1.2.0",
"version": "1.3.0",
"license": "Apache-2.0",

@@ -41,8 +41,8 @@ "author": "lopatnov",

"devDependencies": {
"@lopatnov/rollup-plugin-uglify": "^2.1.0",
"@lopatnov/rollup-plugin-uglify": "^2.1.1",
"@types/jest": "^26.0.23",
"@types/typescript": "^2.0.0",
"jest": "^27.0.3",
"jest-config": "^27.0.3",
"rollup": "^2.50.5",
"jest": "^27.0.6",
"jest-config": "^27.0.6",
"rollup": "^2.52.7",
"rollup-plugin-commonjs": "^10.1.0",

@@ -53,6 +53,6 @@ "rollup-plugin-json": "^4.0.0",

"rollup-plugin-typescript2": "^0.30.0",
"terser": "^5.7.0",
"ts-jest": "^27.0.2",
"typescript": "^4.3.2"
"terser": "^5.7.1",
"ts-jest": "^27.0.3",
"typescript": "^4.3.5"
}
}

@@ -16,3 +16,3 @@ # @lopatnov/namespace [![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fnamespace)](https://twitter.com/intent/tweet?text=I%20want%20to%20share%20TypeScript%20library:&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fnamespace)

[![Patreon](https://img.shields.io/badge/Donate-Patreon-informational)](https://www.patreon.com/lopatnov)
[![sobe.ru](https://img.shields.io/static/v1?label=sobe.ru&message=%D0%9A%D0%BD%D0%B8%D0%B3%D0%B8&color=yellow&logo=data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAArlBMVEUAAAD//////////////////////////////////////////////////////////////////PP/3l7/9c//0yb/zAD/6ZP/zQf/++7/3FD/88X/0h7//v7/5oX/zATUqQDktgD/5HjQpgAFBACQcwD/zw/fsgCOcQD6yADZrQD2xAD8yQDnuADxwADcsADbrwDpugD3xQD5xwDjtQDywQD+ywD9ygDvvwD7yAD/1jRaObVGAAAAEHRSTlMAA3zg707pEJP8MMUBYN5fiwXJMQAAAAFiS0dEAf8CLd4AAAAHdElNRQflBgMAAxO4O2jCAAAAuElEQVQoz42S1w7CMAxFS8ueYZgNLZuyRynw/z9GdtxIkbgPceQT6Tq2vZwfEKx8wRPyiaViSYDABqQsAMq0OzxUqhbo9kBcavUM6A9AAtJAYDgC0ID7i+t4AghwfxanszlAGBnA/Flc0MfL1doA5s/ChoLtbg8QI392gpIBzf/AwYAWAsdTrIE05/nz5Xq7S6DKpenHM0pe+o/qg5Am74/0ybTkm+q6wG4iltV2LTko52idy+Banx9RYiS6Vrsc3AAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wNi0wM1QwMDowMzoxOCswMDowMLvSSCkAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDYtMDNUMDA6MDM6MTgrMDA6MDDKj/CVAAAAAElFTkSuQmCC)](https://sobe.ru/na/tech_knigi)
[![sobe.ru](https://img.shields.io/static/v1?label=sobe.ru&message=%D0%91%D0%BB%D0%B0%D0%B3%D0%BE%D0%B4%D0%B0%D1%80%D0%BD%D0%BE%D1%81%D1%82%D1%8C&color=yellow&logo=data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAArlBMVEUAAAD//////////////////////////////////////////////////////////////////PP/3l7/9c//0yb/zAD/6ZP/zQf/++7/3FD/88X/0h7//v7/5oX/zATUqQDktgD/5HjQpgAFBACQcwD/zw/fsgCOcQD6yADZrQD2xAD8yQDnuADxwADcsADbrwDpugD3xQD5xwDjtQDywQD+ywD9ygDvvwD7yAD/1jRaObVGAAAAEHRSTlMAA3zg707pEJP8MMUBYN5fiwXJMQAAAAFiS0dEAf8CLd4AAAAHdElNRQflBgMAAxO4O2jCAAAAuElEQVQoz42S1w7CMAxFS8ueYZgNLZuyRynw/z9GdtxIkbgPceQT6Tq2vZwfEKx8wRPyiaViSYDABqQsAMq0OzxUqhbo9kBcavUM6A9AAtJAYDgC0ID7i+t4AghwfxanszlAGBnA/Flc0MfL1doA5s/ChoLtbg8QI392gpIBzf/AwYAWAsdTrIE05/nz5Xq7S6DKpenHM0pe+o/qg5Am74/0ybTkm+q6wG4iltV2LTko52idy+Banx9RYiS6Vrsc3AAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wNi0wM1QwMDowMzoxOCswMDowMLvSSCkAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDYtMDNUMDA6MDM6MTgrMDA6MDDKj/CVAAAAAElFTkSuQmCC)](https://sobe.ru/na/tech_knigi)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-lopatnov-informational?style=social&logo=linkedin)](https://www.linkedin.com/in/lopatnov/)

@@ -71,2 +71,23 @@

### attach namespace to a current object
```ts
let shapes = {
color: "green",
count: 3
};
let shapesSpace = Namespace.attach(shapes);
shapesSpace.namespace('Triangles');
shapesSpace.namespace('Circles');
shapesSpace.namespace('Rectangles.Squares');
console.log(shapesSpace.exists('Triangles')); // true
console.log(shapesSpace.exists('Circles')); // true
console.log(shapesSpace.exists('Rectangles.Squares')); // true
console.log(shapesSpace.color); // "green"
console.log(shapesSpace.count); // 3
console.log(shapes === shapesSpace); // true
```
#### checking that object inside namespace exists

@@ -73,0 +94,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc