UNPKG

5.57 kBMarkdownView Raw
1**Protege is a versatile NodeJS extension library that aims to make code as simple as possible**
2
3
4## Installation
5
6To install Protege, use [npm](http://github.com/isaacs/npm):
7
8 $ npm install -g protege
9
10## Usage
11
12```require('protege')``` - it's that easy
13
14### Object
15####These apply to all types, some are Object specific though
16```
17.clone() - Duplicates the object into a new reference
18.clear() - Removes all keys and values from the objects
19.concat(source) - Adds all properties/values from source to object.
20 (optional) overwrite = true will overwrite existing values with source values
21.merge(source, overwrite, deep) - Merge source properties/values into object.
22 (optional) overwrite = true will overwrite existing values with source values
23 (optional) deep = true will initiate a deep merge, merging descriptors and non-enumerable properties
24
25.extend(source) - Alias for merge
26.unique(merge) - Returns a unique copy of the object. (optional) merge will merge values for duplicate keys into arrays instead of removing them
27
28Object.isEmpty(object) - Returns true if object is empty
29Object.isObject(object) - Returns true if object is an object
30Object.isArray(object) - Returns true if object is an array
31Object.isElement(object) - Returns true if object is a DOM element
32Object.isBoolean(object) - Returns true if object is a boolean
33Object.isNumber(object) - Returns true if object is a number
34Object.isString(object) - Returns true if object is a string
35Object.isFunction(object) - Returns true if object is a function
36Object.isXML(object) - Returns true if object is an XML object
37
38.keys() - Returns all keys in the object
39.values() - Returns all values in the object
40
41.getKey() - Returns first key in object
42.getValue() - Returns first value in object
43.getKeys(value) - Returns all keys for the corresponding value
44.getValues(key) - Returns all values for the corresponding key
45
46.remove(key) - Removes key from object
47
48.stringify() - Returns JSON string for object
49.prettify() - Returns a human readable JSON string for object
50```
51
52### Array
53####These also apply to String (since String is just an array after all) but some are only really useful for true arrays
54```
55.clone() - Duplicates the array into a new reference.
56
57.merge(arr) - Adds array arr to array
58.unique() - Returns a copy of the array with duplicates removed
59.flatten() - Returns a one-dimensional copy of the array
60.compact() - Returns a copy of the array with all undefined and null items removed
61.intersect(arr) - Returns an array of all items in both arr and the array
62
63.size() - Returns size of array
64.first() - Returns first value or array or undefined
65.last() - Returns last value or array or undefined
66
67.replace(value, newval) - Replaces first instance of value with newval
68.replaceIndex(index, value) - Replaces item at index with value
69.replaceAll(value, newval) - Replaces all instances of value with newval
70.remove(value) - Removes first instance of value from array
71.removeAll(value) - Removes all instances of value from array.
72.removeAllIgnoreCase(value) - Removes all instances of value from array ignoring case
73.removeIndex(idx) - Removes index of idx from array
74```
75
76### String
77```
78.upcase() - Alias for toUpperCase(), inspired by Ruby syntax
79.downcase() - Alias for toLowerCase(), inspired by Ruby syntax
80
81.strip() - Alias for trim(), inspired by Ruby syntax
82.rstrip() - Alias for trimRight(), inspired by Ruby syntax
83.lstrip() - Alias for trimLeft(), inspired by Ruby syntax
84
85.replaceAll(value, newval) - Replaces all instances of value with newval
86
87.startsWith(value) - Returns true if string starts with value, inspired by Java syntax
88.endsWith(value) - Returns true if string ends with value, inspired by Java syntax
89.startsWithIgnoreCase(value) - Returns true if string starts with value ignoring case, inspired by Java syntax
90.endsWithIgnoreCase(value) - Returns true if string ends with value ignoring case, inspired by Java syntax
91
92.contains(value) - Returns true if the string contains value, inspired by Java syntax
93.containsIgnoreCase(value) - Returns true if the string contains value ignoring case, inspired by Java syntax
94.equalsIgnoreCase(value) - Returns true if the string equals value ignoring case, inspired by Java syntax
95```
96
97## Examples
98
99You can view further examples in the [example folder.](https://github.com/Contra/protege/tree/master/examples)
100
101## Contributors
102
103- [Contra](https://github.com/Contra)
104
105## LICENSE
106
107(MIT License)
108
109Copyright (c) 2011 Contra <contra@australia.edu>
110
111Permission is hereby granted, free of charge, to any person obtaining
112a copy of this software and associated documentation files (the
113"Software"), to deal in the Software without restriction, including
114without limitation the rights to use, copy, modify, merge, publish,
115distribute, sublicense, and/or sell copies of the Software, and to
116permit persons to whom the Software is furnished to do so, subject to
117the following conditions:
118
119The above copyright notice and this permission notice shall be
120included in all copies or substantial portions of the Software.
121
122THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
123EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
124MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
125NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
126LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
127OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
128WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
129
\No newline at end of file