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() |
Please refer to the detailed documentation: list.test.ipynb
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"})
# betterdict: BetterDict({'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)
# sealedDict: SealedBetterDict({'very': 'good'})
sealedDict.very = "bad"
# sealedDict: SealedBetterDict({'very': 'bad'})
sealedDict.a = 1
# AttributeError: SealedDict object does not support assigning new attributes
frozenDict = DictUtils.freeze(betterdict)
# sealedDict: FrozenBetterDict({'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() |
Please refer to the detailed documentation: dict.test.ipynb
BetterString
Because many methods in JavaScript's String are not very useful (mainly difficult to implement), we have only implemented a portion of them.
Please refer to the detailed documentation: string.test.ipynb
License
GPLv3
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file EasyObj-0.2.8.tar.gz.
File metadata
- Download URL: EasyObj-0.2.8.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec69302d3c46a50aec8d4b69a066f207bee16a2c62db6294e4061ea8fc850ab
|
|
| MD5 |
58ce6ac3e7cacbb39c5e89b04aa29f04
|
|
| BLAKE2b-256 |
2065745085f5ee0b35e24b77f1c9cfbe4de400607b69e2d42d507609e1797716
|
File details
Details for the file EasyObj-0.2.8-py3-none-any.whl.
File metadata
- Download URL: EasyObj-0.2.8-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c64ef320c16c47fe177f354238948c6aa5786df894c217cad8589bd51893a2c4
|
|
| MD5 |
df1fca73c7ad3a79c80dab2412082163
|
|
| BLAKE2b-256 |
1abcfd1e1774463a44e91e5bf1c20b244a72dea44cfc3ed9eaba62cdda09a4f0
|