Skip to main content

EasyObj lets you manipulate objects as easily as in JavaScript.

Project description

EasyDict

EasyObj lets you manipulate objects as easily as in JavaScript.

Installation

pip install easyobj

Usage

Better List

from EasyObj import BetterList

betterlist = BetterList([1, 2, 3, 4, 5])
# betterlist: BetterList([1, 2, 3, 4, 5])

print(betterlist.length)
# 5

betterlist.append(6)
# betterlist: BetterList([1, 2, 3, 4, 5, 6])

print(betterlist.join(" "))
# '1 2 3 4 5 6'

print(betterlist.filter(lambda x: x >= 4))
# BetterList([4, 5, 6])

print(betterlist.concat(["a", "b", "c"]))
# BetterList([1, 2, 3, 4, 5, 6, 'a', 'b', 'c'])

print(betterlist.map(lambda x: x * 2))
# BetterList([2, 4, 6, 8, 10, 12])

And so on...

Most Methods are exactly the same as the Array object methods in JavaScript.

But since Python does not support using reserved words as method names, we have converted some method names:

JavaScript Python
Array.prototype.with() EasyObj.BetterList._with()
Array.from() EasyObj.BetterList._from()

Better Dict

Because it is difficult to implement many of the features of JavaScript's Object in Python, we only implemented a part of them.

Each BetterDict object will perform an operation similar to EasyDict, converting a normal dictionary into a nested BetterDict object.

from EasyObj import BetterDict

betterdict = BetterDict({"very": "good"})
# {'very': 'good'}

betterdict.very
# 'good'

Due to Python syntax limitations, we cannot add new methods to the BetterDict class like in JavaScript, so we need to introduce another DictUtils class to implement some of the features in JavaScript

from EasyObj import DictUtils

DictUtils.keys(betterdict)
# ['very']

EasyObj also implements the Object.seal and Object.freeze methods, which convert the BetterDict object into a SealedBetterDict and FrozenBetterDict object.

sealedDict = DictUtils.seal(betterdict)
# {'very': 'good'}

sealedDict.very = "bad"
# {'very': 'bad'}

sealedDict.a = 1
# AttributeError: SealedDict object does not support assigning new attributes

frozenDict = DictUtils.freeze(betterdict)
# {'very': 'good'}

sealedDict.very = "bad"
# AttributeError: SealedDict object does not support assigning new attributes

sealedDict.a = 1
# AttributeError: SealedDict object does not support assigning new attributes

Due to Python syntax limitations, we have converted some method names:

JavaScript Python
Object EasyObj.DictUtils
Object.prototype.isPrototypeOf() EasyObj.DictUtils.isPrototypeOf()

Due to Python syntax limitations, the following methods cannot be implemented:

Method name
Object.defineProperty()
Object.getOwnPropertyDescriptor()
Object.getOwnPropertyDescriptors()
Object.getPrototypeOf()
Object.isExtensible()
Object.preventExtensions()
Object.setPrototypeOf()
Object.prototype.hasOwnProperty()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toString()
Object.prototype.valueOf()

License

GPLv3

TODO

  • Implement BetterStr for better strings
  • Implement more JavaScript methods

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

EasyObj-0.2.6.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

EasyObj-0.2.6-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file EasyObj-0.2.6.tar.gz.

File metadata

  • Download URL: EasyObj-0.2.6.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for EasyObj-0.2.6.tar.gz
Algorithm Hash digest
SHA256 fa0c24df02a350ba7d498c3df3b58095db2a6c373e343328f9e0822a41a340e7
MD5 1e6adef0cd1c4edea368d9339fbfa99e
BLAKE2b-256 cd9379baab5c5b237943e672a52809cab5f395108e185025ecaf221d5b25d37e

See more details on using hashes here.

File details

Details for the file EasyObj-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: EasyObj-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for EasyObj-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b61f4b6bb0e5d2398fba4a1626d3e1b87073170ea47e6d630df186e16ab7b5ca
MD5 ad5fa7aa360fd8b7c1c1db967e2d0529
BLAKE2b-256 57170596ae7a7d9e49811250b902a78ef95ae71708562c6f444ac0faddf6e0f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page