# atomy

> JavaScript OOP library

Latest version **2.1.3** (published 2016-03-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install atomy
pnpm add atomy
yarn add atomy
bun add atomy
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2016-03-12 |
| First published | 2016-03-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | undercloud |
| Keywords | JavaScript, js, oop, object |

## Links

- npm: https://www.npmjs.com/package/atomy
- Repository: https://github.com/undercloud/atomy
- Issues: https://github.com/undercloud/atomy/issues
- npm.io page: https://npm.io/package/atomy

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.3 (latest) — 2016-03-12
- 2.1.2 — 2016-03-12
- 2.1.1 — 2016-03-12
- 2.0.1 — 2016-03-12
- 2.0.0 — 2016-03-12

## README

#Atomy
JavaScript OOP

##installaton
`npm install atomy`

Browser
```html
<script src="/path/to/undercloud.atomy.min.js"></script>
```

NodeJS
```js
var Atomy = require('atomy');
```

##class creation
```js
var Animal = Atomy.extend({
  weight: 0,
  abilities: ['eat','breath','see'],
  constructor: function(name) {
    this.name = name;
  },
  say: function() {
    console.log("I'am " + this.name);
  }
})

var dogg = new Animal('Snoop');
var cat  = new Animal('Tom');

dogg.say(); //I'am Snoop
cat.say(); //I'am Tom
```

##inheritance
```js
var Monkey = Animal.extend({
  constructor: function(name) {
    Monkey.superclass.constructor.call(this, name);
  },
  jump: function() {
    console.log('I can jump');
  }
})

var monkey = new Monkey('Joe');

monkey.say(); //I'am Joe
monkey.jump(); //I can jump
```

##extends an existing class
```js
var ReversedArray = Atomy.extend(Array, {
  constructor: function() {
    for (var i in arguments){
      this.push(arguments[i]);
    }
  },
  reverseSort: function() {
    return this.sort().reverse();
  }
})

var ra = new ReversedArray(1,5,3,4,2);
ra.reverseSort(); //[5,4,3,2,1]
```

##instanceof
```js
var Animal = Atomy.extend({/*...*/});

var Monkey = Animal.extend({/*...*/});
var Human  = Monkey.extend({/*...*/});

var Wolf = Animal.extend({/*...*/});
var Dog  = Wolf.extend({/*...*/});

console.log(new Dog() instanceof Wolf); //true
console.log(new Dog() instanceof Animal); //true
console.log(new Dog() instanceof Monkey); //false
```

##constant
```js
var XMath = Atomy.extend({});

XMath.constant('PI', 3.14);

try {
  XMath.PI = 0;
} catch (e) {

}

XMath.PI; //3.14
```
Add constant into existing objects
```js
Atomy.constant(window, 'MYCONST', true);
window.MYCONST = false;
window.MYCONST; //true
```

##private
```js
var Something = Atomy.extend({
  constructor: function() {
    var hiddenProperty = 'Hidden Value';

    Something.prototype.getHiddenProperty = function() {
      return hiddenProperty;
    };
  }
});

var s = new Something();
s.getHiddenProperty(); //Hidden Value
```

##inject
Extend object prototype
```js
var Something = Atomy.extend({/*...*/});

Something.inject({
  foo: 'Bar',
  getFoo: function() {
    return this.foo;
  }
});

var some = new Something();
some.getFoo(); //Bar
```
Inject single property
```js
Something.inject('square', function(x) {
  return x * x;
});

some.square(3); //9
```
Inject into existing objects
```js
Atomy.inject(Array, 'reverseSort', function() {
  return this.sort().reverse()
});

var a = [6,7,3,4,2];
a.reverseSort(); //[7, 6, 4, 3, 2]
```

##share
Same as `Atomy.inject` but extends only static context
```js
var Something = Atomy.extend({/*...*/});

Something.share({
  foo: 'Bar',
  getFoo: function() {
    return this.foo;
  }
});

Something.getFoo(); //Bar
```
Share single property
```js
Something.inject('square', function(x) {
  return x * x;
});

Something.square(3); //9
```
Share existing objects
```js
Atomy.share(window.location, 'setHash', function(hash) {
  this.hash = hash;
});

window.location.setHash('goto');
```

##singletone
```js
var Animal = Atomy.extend({});

Animal.__instance__ = null;
Animal.getInstance = function() {
  if(this.__instance__ === null) {
    this.__instance__ = new Animal();
  }

  return this.__instance__;
}

var a = Animal.getInstance();
var b = Animal.getInstance();

a === b //true
```

##namespace
```js
Atomy.namespace('milkyway.solar.earth');
//window.milkyway.solar.earth

var scope = {};
Atomy.namespace('milkyway.solar.earth',scope);
//scope.milkyway.solar.earth

Atomy.namespace('milkyway.solar.earth.life').Animal = Atomy.extend({
  /*...*/
});

var animal = new milkyway.solar.earth.life.Animal();
```

##isset
```js
Atomy.isset('window.Array.prototype.sort'); //true
Atomy.isset('sort', Array.prototype); //true

var Animal = Atomy.extend({
  say: function() {
    /*...*/
  }
});

var monkey = new Animal();
monkey.isset('say') //true

Animal.abilities = []; 
Animal.isset('abilities'); //true
```

##toString
```js
var Animal = Atomy.extend({
  toString: function() {
    return '[object Atomy]';
  }
});
```

---
_Source: https://npm.io/package/atomy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
